Print

Zoho Creator: Button on Report for Merging Multiple Selected Records

What?
The aim of this article is to document how you can display a Creator report to the user, that they can select (tickbox) multiple records in that report, and then have a button that loops through all the selected (ticked) records. The example below documents a report of Quotes where we want to merge all the product line items of each quote into one single quote.
Zoho Creator - Report Multiple Records Selected
Why?
I've written this article because I keep forgetting on how to do this. I have a specific order of steps on how I do this, you may find other ways but this is one that works for me.

How?
So here's an overview and then we'll go into more detail:
  1. Create a function that accepts a form of records
  2. Create a workflow that understands the function parameters

Create a function
Why are we doing this first? Well when I create a workflow, it will ask me to run a function, the Creator workflow process will then read what datatype of a parameter I'm sending to the function.

  1. So in "Edit this application" > go to Workflow > Functions > New Function: give the function a name
  2. select "Deluge" as the language
  3. give it a Namespace (for this example I will leave this on "Default")
  4. and set the return type (again in this example, I will leave this as "void")
  5. for Arguments
    • Specify a parameter name of your choosing, in our example I am going to prefix it with "l_" (for list) and the plural of what kind of records I am sending as parameters (in this case "Quotes").
    • As the actual parameter value, select the form which is the singular of the records that you are sending (in my example here I have a form called "Partners Quote".
Zoho Creator - Creating a function with the Form passed as a parameter
Within your function you can use the following as a reference. In theory, you could loop through each submitted quote but I do a call at the beginning of each iteration of the loop to retrieve all the data in each record r_QuoteDetails = Partners_Quote[ID == r_Quote.ID];. In the example below, this is a merging process of each quote which only contains 1 line item and not a subform of line items. You could adapt the following to also loop through a subform found on each record but for this simple demonstration, we will assume that each record only has 1 item.
copyraw
void emailMergedReceipts(Partners_Quote l_Quotes)
{
    v_ContactFname = "";
    v_ContactSname = "";
    v_SubTotal = 0.0;
    v_TotalVat = 0.0;
    v_Total = 0.0;
    v_Total_Tax_Factor = 0.2;
    for each  r_Quote in l_Quotes
    {
        r_QuoteDetails = Partners_Quote[ID == r_Quote.ID];
        v_ContactFname = r_QuoteDetails.Contact_Name.first_name;
        v_ContactSname = r_QuoteDetails.Contact_Name.last_name;
        v_LineItem_Name = r_QuoteDetails.Product_Name;
        v_LineItem_Desc = r_QuoteDetails.Product_Description;
        v_LineItem_Price = r_QuoteDetails.Product_List_Price;
        v_LineItem_Quantity = r_QuoteDetails.Product_Quantity;
        v_LineItem_TaxAmount = r_QuoteDetails.Product_Tax_Amount;
        //
        v_LineItemTotalExclVat = v_LineItem_Price * v_LineItem_Quantity;
        v_LineItemTotalVat = v_LineItemTotalExclVat * v_Total_Tax_Factor;
        v_LineItemTotal = v_LineItemTotalExclVat + v_LineItemTotalVat;
        v_SubTotal = v_SubTotal + v_LineItemTotalExclVat;
        v_TotalVat = v_TotalVat + v_LineItemTotalVat;
        v_Total = v_Total + v_LineItemTotal;
    }
    //
    // other actions you want to do after all quotes looped through
    //
}
  1.  void emailMergedReceipts(Partners_Quote l_Quotes) 
  2.  { 
  3.      v_ContactFname = ""
  4.      v_ContactSname = ""
  5.      v_SubTotal = 0.0
  6.      v_TotalVat = 0.0
  7.      v_Total = 0.0
  8.      v_Total_Tax_Factor = 0.2
  9.      for each  r_Quote in l_Quotes 
  10.      { 
  11.          r_QuoteDetails = Partners_Quote[ID == r_Quote.ID]
  12.          v_ContactFname = r_QuoteDetails.Contact_Name.first_name; 
  13.          v_ContactSname = r_QuoteDetails.Contact_Name.last_name; 
  14.          v_LineItem_Name = r_QuoteDetails.Product_Name; 
  15.          v_LineItem_Desc = r_QuoteDetails.Product_Description; 
  16.          v_LineItem_Price = r_QuoteDetails.Product_List_Price; 
  17.          v_LineItem_Quantity = r_QuoteDetails.Product_Quantity; 
  18.          v_LineItem_TaxAmount = r_QuoteDetails.Product_Tax_Amount; 
  19.          // 
  20.          v_LineItemTotalExclVat = v_LineItem_Price * v_LineItem_Quantity; 
  21.          v_LineItemTotalVat = v_LineItemTotalExclVat * v_Total_Tax_Factor; 
  22.          v_LineItemTotal = v_LineItemTotalExclVat + v_LineItemTotalVat; 
  23.          v_SubTotal = v_SubTotal + v_LineItemTotalExclVat; 
  24.          v_TotalVat = v_TotalVat + v_LineItemTotalVat; 
  25.          v_Total = v_Total + v_LineItemTotal; 
  26.      } 
  27.      // 
  28.      // other actions you want to do after all quotes looped through 
  29.      // 
  30.  } 
Save your function and click on "Done" to ensure it's all saved in the system.

Create the workflow
Now go to a the "Design" mode of the report that contains the forms you want to be able to merge (multiple selection) and click on the "Actions" tab then on the 'plus' icon under "For Multiple Records" to add a button. In our example, the report is called "Your Quote History" and it is a report on the form "Partners Quote":
Zoho Creator - Create a button on the report
Add new action item
  1. Name your action item
  2. Name the workflow
  3. Execute the action for Collection of record (this step is very important!)
And you should have something like the following:
Zoho Creator - Add an action for Multiple Records
Click through on "Add New Action":
Zoho Creator - Add New Action
Select "Deluge Script"
Zoho Creator - Action Type: Deluge Script
Select an event: Run a function:
Zoho Creator - Action Type: Deluge Script
And the next screen is why I created the function in advance: Zoho Creator - Run the function created earlier, specify the FORM OBJECT as a the field parameter
"Save" that then click on "Done" to make sure it's all registered in the system. Then click on "Create" to add your button to the report action "For Multiple Records".

Amazing! You're all done! Go test it by going to the report, hover the mouse over each row and a tickbox will appear, tick a few and click on your newly made button (as per the first screenshot on this article).
Category: Zoho :: Article: 735