Virtual Attributes

When an attribute is defined as virtual, it means that it stores no data value, and is defined by its read and write access methods.

BPM Object attributes can be real or virtual. Defining an attribute as real means that the attribute contains an actual data value. When an attribute is defined as virtual, it means that it contains no data value, and is defined by its read and write access methods.

Virtual Attribute Definition

You create a virtual attribute the same way you create a real attribute, except that you select Virtual in the Storage Constraints section of the attribute editor. When you do this, Studio creates two methods

For example, if you designed a BPM Object to obtain weather data, you would likely include a temperature attribute. You could implement the temperature in degrees Celsius in an attribute called tempCelsius.

If you wanted to also handle the temperature in degrees Fahrenheit, you could implement a virtual attribute tempFahrenheit which would be implemented as follows:

Read access:
return tempCelsius * 1.8 + 32
Write access:
tempCelsius = (value - 32) / 1.8

Virtual Attributes from Process Business Language Code

In Process Business Language code, you access a virtual attribute the same way you access a real attribute. However, you can only access the variable in whatever modes are defined for it (read access or write access or both). For example, a total virtual attribute in the invoice BPM Object has the following read access method:
amount as Decimal(2)
amount = 0

for each item in items do
	amount = amount + item.amount
end

return amount
In this fragment of code, items is a group, and amount is a decimal value representing the cost of each item.
To obtain total value from code, you use:
invoice.total
There is no write method for the total attribute, nor would it make sense to have one (since by definition the total must equal the sum of the amounts), so you would not set it to any value in code.
The tempFahrenheit virtual attribute we defined above does have both read access and write access. To write, use:
weather.tempFarenheit = 70.7
Remember that the 70.7 value will not be stored. Instead, when this line of code is executed, weather.tempCelsius will take on a value of 21.5.
To read, use:
display weather.tempFarenheit
The 70.7 value will be displayed.