Overview
GELLO code will be used to calculate the value of 'Total Cost'. It will retrieve the values from 'Number' and 'Cost' and return the result of one multiplied by the other. Click on the RHS in the pane next to IsCalculated for the 'Total Cost'. Then click on on the far right hand side of this pane, which is now a white background colour.
The first bit of GELLO code is nearly always this:
let o:observation = parameter[1] |
Now let's set up a local variable to hold the value for instances of the archetype where 'Cost' is entered. Add the following code:
let Cost: Integer = if o.isdefined() then o.find_observation('1.2').value_asPQ().value else 0.0 endif |
Same again for 'Number' - a bit simpler as it is already a number:
let Number: Integer = if o.isdefined() then o.find_observation('1.3').value_asReal() else 0.0 endif |
Next thing is to do the algorithm that produces the result:
let Result: Integer = Cost * Number |
But 'Total Cost' is a Physical Quantity*, so the result needs to be returned in this form. This line of code just declares what needs to be returned by the GELLO v. 1 expression:
Factory.PhysicalQuantity (Result, '$') |
* It isn't really, but we are using this apple example to learn about such things. |