Sum up multiple Quotes Grand Total for a deal.

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 function:

For the Quotes Module:

  • Go to Setup > Automations > Actions > Functions > Configure Function > Write your own.
  • Provide a name for the function. For example: "Sum up grand total - 1".
  • Select the module to be associated as Quotes. Add a description(optional).
  • Copy the code given below.
  • Click "Edit arguments".
  • Enter the name as "dealId" and select the value as "Deal Id".
  • Click Save & Execute Script.
  • Save the changes.

 

For the Deals Module:

  • Go to Setup > Automations > Actions > Functions > Configure Function > Write your own.
  • Provide a name for the function. For example: "Sum up grand total - 1".
  • Select the module to be associated as Deals. Add a description(optional).
  • Copy the code given below.
  • Click "Edit arguments".
  • Enter the name as "dealId" and select the value as "Deal Id".
  • Click Save & Execute Script.
  • Save the changes.

 

The Code: For V1 API - Old Editor:

For the Quotes Module:

dealIdStr = input.dealId.toString();
RelatedQuotes = zoho.crm._getRelatedRecords("Quotes", "Deals", dealIdStr);
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("Deals", dealIdStr, mp);
info mp;
info update;

For the Deals Module:

dealIdStr = input.dealId.toString();
RelatedQuotes = zoho.crm._getRelatedRecords("Quotes", "Deals", dealIdStr);
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("Deals", dealIdStr, mp);
info mp;
info update;

The Code: For V2 API - DRE Editor:

For the Quotes Module:

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;

For the Deals Module:

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;

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!

Return to Tips