Function-6: Sum up multiple quotes grand total associated to a deal.

Function-6: Sum up multiple quotes grand total associated to a deal.


Welcome back everyone!

Last week, we learnt how to - create quotes from deals with just the click of a button. This week, let's look at a custom function that sums up total value across the quotes linked to a specific deal.

Business scenario:

Assume you created a deal pertaining to a particular product category that your organization is engaged. This deal is linked with all the related quote records across customers. Or another deal related to all businesses done in the current fiscal year with a particular customer, and linked all the related quote records. While most businesses follow convention, that is - qualify a lead, create an account and a contact, link it to a deal, create a quote and such. However, there are some of us who jump these conventions, right? :) Zoho CRM offers you the flexibility of such customizations to fit your business requirements. Customizations with the added ability of automation lets you sum up all the quote values related to a deal.

Besides, you can use it for other modules as well by simply changing the module name in the code accordingly.

Getting started with the custom function:

For the Quote module:

  • Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
  • Provide a name for the custom function. For example: “Sum up deals as a field - 1”. Add a description(optional).
  • Select the module as Quotes. Add a description(optional).
  • Click “Free flow scripting”.
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “potId” and select the value as “Potential Id”.
  • Save the changes.

For the Deals module:

  • Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
  • Provide a name for the custom function. For example: “Sum up deals as a field - 1”. Add a description(optional).
  • Select the module as Deals. Add a description(optional).
  • Click “Free flow scripting”.
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “potId” and select the value as “Potential Id”.
  • Save the changes.

Note:
The name of the module "Deals" should be mentioned as "Potentials" in the code, no need to change that name to Deals .

The Script:

For the Quotes Module:
Code for Version 2.0 API:

RelatedQuotes = zoho.crm.getRelatedRecords("Quotes", "Deals", potId.toLong(),1,200);
//info RelatedQuotes;
total = 0.0;
for each ele in RelatedQuotes
{
grand =ifnull(ele.get("Grand_Total"),"0.0").toDecimal();
total = (total + grand);
}
mp = map();
mp.put("Amount", total);
update = zoho.crm.update("Deals", potId.toLong(), mp);
info mp;
info update;

Code for Version 1.0 API:

potIdStr = input.potId.toString();
RelatedQuotes = zoho.crm.getRelatedRecords("Quotes", "Potentials", potIdStr);
info RelatedQuotes;
total = 0.0;
for each ele in RelatedQuotes
{
grand =ifnull(ele.get("Grand Total"),"0.0").toDecimal();
total = (total + grand);
}
mp = map();
mp.put("Amount", total);
update = zoho.crm.updateRecord("Potentials", potIdStr, mp);
info mp;
info update;
For the Deals Module:
Code for Version 2.0 API:

RelatedQuotes = zoho.crm.getRelatedRecords("Quotes", "Deals", potId.toLong(),1,200);
//info RelatedQuotes;
total = 0.0;
for each ele in RelatedQuotes
{
grand =ifnull(ele.get("Grand_Total"),"0.0").toDecimal();
total = (total + grand);
}
mp = map();
mp.put("Amount", total);
update = zoho.crm.update("Deals", potId.toLong(), mp);
info mp;
info update;

Code for Version 1.0 API:

potIdStr = input.potId.toString();
RelatedQuotes = zoho.crm.getRelatedRecords("Quotes", "Potentials", potIdStr);
info RelatedQuotes;
total = 0.0;
for each ele in RelatedQuotes
{
grand =ifnull(ele.get("Grand Total"),"0.0").toDecimal();
total = (total + grand);
}
mp = map();
mp.put("Amount", total);
update = zoho.crm.updateRecord("Potentials", potIdStr, mp);
info mp;
info update;






Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. See you all next week with another interesting custom function. Ciao!

Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.