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.
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:
- Create a function that accepts a form of records
- 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.
- So in "Edit this application" > go to Workflow > Functions > New Function: give the function a name
- select "Deluge" as the language
- give it a Namespace (for this example I will leave this on "Default")
- and set the return type (again in this example, I will leave this as "void")
- 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".
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.
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 // }
- 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
- //
- }
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":
Add new action item
- Name your action item
- Name the workflow
- Execute the action for Collection of record (this step is very important!)
Click through on "Add New Action":
Select "Deluge Script"
Select an event: Run a function:
And the next screen is why I created the function in advance:
- Select the application (should be the name of your Creator application)
- Select namespace (if following this example, it will be "Default")
- Select function (note that only functions that can receive a list/form object are listed here)
- The argument name should be disabled/read-only, and for field name, select the myForm[Form Object]. (in our example Partners_Quote[FORM OBJECT]):
"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).