Update the account's annual revenue with the sum of its sales orders

Automatically calculate the total value of completed sales orders for an account and display it as annual revenue.

The annual revenue of an account in CRM can give you insights into the value of a customer and their potential for future business opportunities. By tracking annual revenue, businesses can identify high-value customers and tailor their marketing and sales efforts accordingly. A system field within the accounts module lets you manually input an account's annual revenue. However, what if you want to view this value auto-populated and readily available on the account record? Well, it's just a function away.

With our low-code tools, you can easily calculate the total value of completed sales orders for an account and display it as annual revenue. You just need to create a custom function and connect it to a workflow rule for the Accounts module.

Permissions and availability

  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a workflow rule for the Accounts module that will automatically update the Annual Revenue field whenever any changes are made. Learn more
  • Write a custom Deluge function that sums the value of an account's closed sales orders and link it up with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a workflow rule

Follow the steps below to create a workflow rule in your Zoho CRM account:

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Accounts from the module dropdown list.
  3. Provide a name for the rule. For example: "Compute Annual Revenue". 
  4. Add a description, if required, then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Edit from the drop-down.
    2. Check the box for Repeat this workflow whenever an Account is edited.
    3. Click Next.
  6. In the Which accounts would you like to apply the rule to? section, select All Accounts and click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a Name and optional description for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Accounts - Account Id, name it as accountId, then click Save.
    4. Click Save & Execute Script.
  10. Click Save on the workflow rule page.
Create Workflow Rule

The code

Code Copied
relatedso = zoho.crm.getRelatedRecords("SalesOrders","Accounts",accountId.toLong());
//info relatedso;
totalgrand = 0.0;
for each so in relatedso
{
if( so.get("Status") == "xxxxx")
{
grand = ifnull(so.get("Grand_Total"),"0.0").toDecimal();
totalgrand = totalgrand + grand;
}
}
mp=map();
mp.put("Annual_Revenue",totalgrand);
update = zoho.crm.updateRecord("Accounts", accountId.toLong(), mp);
info mp;
info update;

Notes

  • Replace 'xxxxx' with the sales order's closed status value in your CRM (e.g. Delivered).
  • Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more

Test the solution

  1. Click the Accounts tab.
  2. Open an account record that contains sales orders in the closed state (see: Related List - Sales Orders).
    If necessary, create a new sales order for the account.
  3. Edit the account record and click Save.
  4. See whether the account's closed sales orders' total value gets updated in the Annual Revenue field.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleAccounts
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityLow
  • Implementation Time15 minutes

Features used in the solution

Workflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!