A virtual attribute is not a stored data value like a regular attribute. Instead, when
you access the value of a virtual attribute, code calculates the value to be returned.
You use a virtual attribute to implement the total amount of the expense report. In
programming terms, you can think of a virtual attribute as a method or a pair of
methods to either set or get a value.
To define a virtual attribute:
-
In the Project Navigator, right-click on the ExpenseReport BPM Object
(
), and click
(
).
The
Attribute dialog box appears.
-
Enter the word total in the Name field.
-
Select Decimal from the Type drop-down list, and click
OK.
The
total attribute is created, and the attribute 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 is now virtual.
-
In the Project Navigator, expand the total
attribute.
Two methods are shown: Read Access (
) and Write Access (
).
-
Double-click Read Access.
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 (a line with
return 0 should be all that you find), 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.