This article was updated on 25. June 2020 with some material showing how to test the behaviour of the
Formula Engine function
attribute with Adetta, our solution for testing Asset Control custom code.
One of the most used Formula Engine functions is certainly attribute(). This allows you to get the values of static attributes of ADOs.
In its simplest form, you can use it to retrieve the current value of a single attribute of a single ADO:
acdba@acbox:~$ echo "attribute('BB.00-2147', 'BB_DX120');" | ac_evalform - US acdba@acbox:~$
For profiled attributes, if you want to know what the value was at a given point in time, you would add the DATE option as shown:
acdba@acbox:~$ echo "attribute('BB.00-2147', 'BB_DX120', ['DATE=20180319:235959']);" | ac_evalform - GE acdba@acbox:~$
(There are other options available. I recommend you consult the user manual.)
It is also important to know that the returned structure depends on whether you query for a single ADO, as list of ADOs, a single attribute or a list of attributes:
|attribute() call||Input format||Output||Output format|
|attribute(‘BB.00-2147’, ‘BB_DX120’)||single ADO, single attribute||‘US’||a single value|
|attribute(‘BB.00-2147’, [‘BB_DX120’, ‘BB_DX122’])||single ADO, list of attributes||[‘US’, ‘EX’]||a list of values|
|attribute([‘BB.00-2147’,‘BB.00-2151’], ‘BB_DX120’)||list of ADOs, single attribute||[‘US’, ‘CA’, ‘BB.00-2147’, ‘BB.00-2151’]||list containing of values followed by ADOs|
|attribute([‘BB.00-2147’,‘BB.00-2151’], [‘BB_DX120’, ‘BB_DX122’])||list of ADOs, list of attributes||[[‘US’, ‘EX’, ‘BB.00-2147’], [‘CA’, ‘T4’, ‘BB.00-2151’]]||list of lists, one per ADO, with all values followed by the ADO ID|
In practice, you will use the first, second and fourth form most as they yield structures that are easier to reason about and process. Also, you can always enforce the fourth form by working with both ADO and attribute lists, even if they contain only one element.
The take-away message here is: You have to control the structure of your inputs to be able to predict the structure of your output.
Testing the different return structures in Adetta looks like this:
We hope that was useful. Thank you for reading.