Update deal with sum of all products

Automatically update the deal amount by summing the unit prices of all associated products, and thereby improve visibility into your revenue pipeline.

Zoho CRM's deal dashboards—particularly the Pipeline by Stage widget—are among the most valuable tools for sales leadership. They provide a clear picture of your revenue pipeline across various deal stages and help you determine whether you're on track to meet your sales targets and identify where corrective action may be needed. However, the accuracy of these dashboards depends entirely on the correctness of the Amount field in each deal.

Manually entering the deal amount by summing the unit prices of all associated products can introduce human error, inconsistencies, and delays. In some cases, the field may be left blank initially and updated later, reducing the reliability of your pipeline visibility. What if the deal amount could be automatically updated at the click of a button? This is where our low-code tools can come in handy.

You can create a custom button paired with a function that automatically sums the unit prices of all related products and updates the corresponding deal record. Sound interesting? Read on to learn more.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Modules Customization permission can create custom buttons.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a Zoho CRM connection with the required scope, as detailed in the "Create a connection" section below. Learn more
  • Write a custom Deluge function that sums the unit prices of all products associated with a deal. Learn more
  • Create and link a button with the custom function, as detailed in the "Create a button" section below. Learn more
  • Test the solution in a sandbox before deploying it to your production environment. Learn more

Create a connection

The first step is to create a connection in your Zoho CRM account:

  1. Go to Setup > Developer Hub > Connections.
  2. Click CreateConnection.
  3. Select Zoho CRM under Default Services.
  4. Specify a Connection Name.
    You will need to enter this name in the code snippet below.
  5. Select the following Scope to request access:
    • ZohoCRM.modules.ALL
  6. Click Create and Connect.
  7. Click Connect, then click Accept to confirm access to the requested scopes.

Create a button

Next, create a button linked to a function in the Deals module.

  1. Navigate to Setup > Customization > Modules and Fields > Deals > Buttons > Create New Button.
  2. Provide a name for the button. For example: "Update Amount".
  3. Add a description (optional).
  4. Choose the layout(s) you want the button to be placed in.
  5. Specify the button placement as In Record and its position on the page as Details.
  6. Select the action to be performed as Writing Function.
  7. Provide a name and display name for the function, then click Create.
  8. In the Deluge script editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Edit Arguments.
    3. Enter the name as potId and set the value as Deals - Deal Id, then click Save.
    4. Save the function.
  9. Select the profiles that can view this custom button.
  10. Click Save.

The code

Code Copied
query_data = Collection();
query_data.insert("fields":"Product_Name,id,Unit_Price");
RelatedPotential = zoho.crm.v8.getRelatedRecords("Products", "Deals", potId.toLong(),1,200,query_data,"connectionname");
//info RelatedPotential;
unitprice = 0.0 ;
for each ele in RelatedPotential
{
unit = ifnull(ele.get("Unit_Price"),"0.0").toDecimal();
unitprice = unitprice + unit ;
}
mp=map();
mp.put("Amount",unitprice);
update=zoho.crm.v8.updateRecord("Deals", potId.toLong(), mp);
info mp;
info update;
return "Amount Updated";

Notes

  • Make sure to use the accurate API names for their corresponding fields (e.g., "Amount") in the code snippet. Learn more
  • Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
  • The Unit Price field is a standard field in the Products module. Make sure it is filled out for all products associated with your deals.
  • The code above demonstrates how to automatically update the deal amount by summing the unit prices of all associated products with a single click. You can use this code for any other module, such as Sales Orders or Quotes, by modifying the module name and parameters.

Tip

  • Configure and test the solution in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to the Deals module.
  2. Open an existing deal record or create a new deal.
  3. Associate one or more products with the deal via the Products related list. Ensure each product has a value in the Unit Price field.
  4. On the Deal Details page, click the "Calculate Amount" button in the top-right corner.
  5. Verify that the button returns the message "Amount updated".
  6. Verify that the Amount field on the deal record is updated with the sum of the unit prices of all associated products.
  7. To validate accuracy, manually add the unit prices of the associated products and compare the total with the value in the Amount 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

  • ModuleDeals
  • Trigger PointCustom Button
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

ConnectionCustom ButtonDeluge 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!