Sorry that it took me so long to get around to answering this one.
If you have a grid object named "Items" in the master form and it contains the field "Cost", then you can access the first and second rows in the grid like this in a trigger:
Code: Select all$CostInFirstRow = @=Items[1]['Cost'];
$CostInSecondRow = @=Items[2]['Cost'];
Note that the grid starts counting from 1, and not 0 like a normal array. If you try to access Items[0]['Cost'] you will get a NULL value. Make sure to embed the grid form in a master form. Note that I use @= (instead of @@) to access the variable because I don't want to add quotes to it.
If you want to sum the cost field you could do it like this:
Code: Select all$lenGrid = count(@=Items);
@=sumGrid = 0;
for ($x = 1; $x <= $lenGrid; $x++)
@=sumGrid += @=Items[$x]['Cost'];
Nonetheless, it isn't necessary to write php code to do this. ProcessMaker will automatically sum a column in a grid if you add the option
function="sum" to the XML definition of the field in the grid form. Here is the sample XML code for a field named "Cost":
Code: Select all<Cost type="text" maxlength="64" validate="Real" size="1" mode="edit" function="sum" mask="" strto="" required="0" readonly="0" dependentfields="" defaultvalue="" sqlconnection="" savelabel="0"> <en>Cost</en>
</Cost>
In the master grid form, the sum will automatically be calculated and displayed below the embedded grid object. (To see an example of this and some javascript to control grid objects, download the process "JS Examples" from
http://library.processmaker.com)
ProcessMaker will automatically create a variable called @=SYS_GRID_AGGREGATE_Items_Cost which you can access from triggers or in subsequent DynaForms if you create a Textbox with the same name.