A virtual attribute is not a stored data value like a regular
attribute. Instead, when you access the value of a virtual attribute, code is
that calculates the value to be returned. You will use a virtual attribute to
implement the total amount of the expense report.
To define a virtual attribute:
- In the
Project Navigator, right-click on the
ExpenseReport BPM Object (
), and click
(
).
The
Atribute dialog box appears.
- Enter
total in the
Name field.
- Select
Decimal from the
Type drop-down list, and click
OK.
The
total attribute is created, and the atrribute editor
for it opens.
- Set the
Decimal Digits to 2.
- In the
Storage Constraints section, set the
Virtual option.
- Click
Save (
) and close the editor.
The
total attribute becomes virtual.
- In the
Project Navigator, expand the
total attribute.
Two methods are shown: Read Access (
) and Write Access (
).
- Double-click on the Read Access icon, or right-click and click
(
).
A PBL (Process Business Language) method editor window
opens. The method is named
read_access_code_total.
- The total attribute is the sum of every item's amount value.
To have the
total attribute return this value, it must be
calculated by adding the amounts of all the items. Remove any existing code,
and enter the following PBL code into the editor exactly as shown, including
capitalization:
amount as Decimal(2)
amount = 0
for each item in items do
amount = amount + item.amount
end
return amount
- Save your changes and close the editor. You do not need to
enter code for the Write method for this attribute.
You have added a virtual attribute to the ExpenseReport BPM object. In
the following task you will define
valid values for the
costCenter attribute.