How to create a dynamic running total in a form

How to create a dynamic running total in a form

Running total can help you to dynamically calculate the cumulative sum of values as new entries are added. This provides real-time insights into accumulating data, enriching analytical capabilities within your application, whether you're monitoring expenses, sales, or any other numerical data.
For example, assume the Zoho Creator application is utilized within an organization for sales-related operations. Users consistently log new sales transactions into the system, and they require instant visibility into the total sales figures as transactions are added. By incorporating a running total feature, users can seamlessly track the cumulative sum of all sales entered in real-time. This empowers them to effectively monitor progress towards achieving targeted sales goals.
  1. Navigate to the form builder of the form in which you want to incorporate the running total. Include two currency fields. Designate one for calculating the total within the form and the other to compute the running total based on the accumulated data from the first currency field.

    In this tutorial, for demonstration purposes, we have used the 'Pay an Invoice' form from the form template, added an additional Currency field 'Running_Total', and set its initial value to '0' from its field properties to calculate the running total for the 'Invoice Amount' currency field already available in the form template.

     

    Form Name

    Form Link Name

    Field Type

    Field Name

    Fied Link Name

    Pay an Invoice

    Pay_an_Invoice

    Currency

    Invoice Amount

    Invoice_Amount

    Currency

    Running Total

    (Initial value: 0)

    Running_Total

     

  2. Create a new workflow to execute on the Successful form submission of the Pay an Invoice form with the record event as Created or Edited.

  3. Click Add New Action > Deluge Script and add the following script to the Deluge editor.
    1. if(Running_Total == 0)
    2. {
    3. //When creating a new record, calculate the sum of all values of the 'Invoice_Amount' field in previous records and update the 'Running_Total' field accordingly.
    4.  newTotal = <Form_Link_Name>[ID != 0].sum(Invoice_Amount);
    5.  input.Running_Total = newTotal;
    6. }
    7. else
    8. {
    9. //When editing a record, update the 'Running_Total' field for the current record as well as for all other records added after it with the new cumulative total. 
    10.  newTotal = <Form_Link_Name>[ ID != 0 && Added_Time <= input.Added_Time].sum(Invoice_Amount);
    11.  input.Running_Total = newTotal;

    12.  for each update_total in <Form_Link_Name>[ ID != 0 && Added_Time > input.Added_Time]
    13.  {
    14.  update_total.Running_Total=newTotal;
    15.  update_total.Running_Total=newTotal + update_total.Invoice_Amount;
    16.  newTotal = newTotal + update_total.Invoice_Amount;
    17.  }
    18. }
  4. Create another workflow to execute on the On Validation of Form Deletion and select the record event as Deleted. This workflow updates the running total for all other records added after the deleted record with the new cumulative total.

  5. Click Add New Action and add the following script to the Deluge editor.
  1. //When deleting a record, update the 'Running_Total' field for all other records added after it with the new cumulative total.
  2. for each update_total in <Form_Link_Name>[ID !=0 && Added_Time >= input.Added_Time]
  3. {
  4.  update_total.Running_Total=update_total.Running_Total - input.Invoice_Amount;
  5. }
You can also choose to hide/disable this auto-incrementing number field to prevent manual user entries. To hide this field:
  1. Create a workflow by selecting record event as Created or Edited and form event as Field rules.

  2. On the subsequent page, click Add New Action, choose Hide fields, set this action to run always, and select the Running Total field.

See how it works


  1. Sum
  2. Currency