UiPath Form Designer - How to Sum multiple line values in a Data Grid component?

UiPath Form Designer - How to Sum multiple line values in a Data Grid component?

Issue Description:
Sometimes in Action Center, it is necessary to create a Form with a Data Grid where the Sum of a column is needed, for example in the screenshot below the Sum of the Amount column has to be displayed in a Currency component (Total Amount).

image.png



Resolution:

The code below steps can be used and adapted in the Currency component that will display the Total Amount:
image.png

To add the above Logic follow the next steps:

  1. Add a Currency component to display the Total Amount of the Sum.
  2. Click on the Edit button of the Currency component, as a recommendation mark the Disabled check box of the display section to make it not editable.
  3. Click on the Logic section and click on Add Logic.
  4. Add a name to the Logic, "Calculate total".
  5. On the Trigger section select the "Simple" type for a particular component when have a specific value (in this example it was triggered for out_IsException that has value true)
  6. Add an Action and name it for example "Sum line items" and select the type "Value".
  7. Finally, add the below code in the Value section:
Note: io_DataTable is the Field Key of the Data Grid
amountTotal = 0;
lineCount = data.io_DataTable.length;
    for (i=0; i<lineCount; i++) {
        amountTotal = (+amountTotal) + (+data.io_DataTable[i].Amount);
    }
return amountTotal;

8. Save Action

After performing all the above steps save all the changes in the Edit section and then save the Form.

Once the project is saved and uploaded to Orchestrator it will work on Action Center as it works in Preview on UiPath Form Designer.