Function-25: Populate the Amount field of a Deal by calculating the number of related products and its unit price.

Function-25: Populate the Amount field of a Deal by calculating the number of related products and its unit price.



Welcome back people!
 
Last week, we looked at a custom function that enabled you to create purchase orders from sales orders at just the click of a button. This week, let's look at another custom function which lets you populate the Amount field in a Deal by calculating the number of products and its unit price.

Business Scenario:

I’m sure you’d agree that the Deal Dashboards is one of the most sought after widgets in Zoho CRM. One of my favorite ones is “Pipeline by Stage” widget that gives a clear indication of your sales pipeline across various deal stages. It gives a fair idea of your revenue pipeline, helps you understand whether you’d be able to meet your sales targets, and take necessary corrective actions if required.

Here comes the tricky part. To make better use of these dashboards, your users have to update all the deal values diligently. Unless the Amount field in the deal is filled accurately, the pipeline dashboard is of little use. Filling the Amount field manually creates a room for error. Moreover, the field could be left blank initially and be updated only at later stages of the deal. Automation removes the scope for such errors. This week’s custom function helps address this problem with ease. The Amount field is dependent on the product details included in the deal. You don't have to calculate the amount that is to be transacted in the deal. This custom function populates the "Amount" field with the information from the "Products" Related List. 

Amount field = (Unit price of P1 + Unit price of P2+....). 

P1, P2, .... denote the individual products in the deal. 

Getting started with the custom function:
  1. Go to Setup > Automation > Actions > Custom Functions > Configure Custom Function > Write your own.
  2. Provide a name for the button. For example: “Auto-populate deal amount”. Add a description(optional).
  3. Choose the module as "Deals".
  4. Click “Free flow scripting”.
  5. Copy the code given below.
  6. Click “Edit arguments”.
  7. Enter the name as “potId” and select the value as “Deal Id”.
  8. Save the changes.
The script:

Code for Version 2.0 API:

RelatedPotential = zoho.crm.getRelatedRecords("Products", "Deals", potId.toLong());
//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.update("Deals", potId.toLong(), mp);
info mp;
info update;

Code for Version 1.0 API:

potIdStr = input.potId.toString();
RelatedPotential = zoho.crm.getRelatedRecords("Products", "Potentials", potIdStr,1,200);
//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.updateRecord("Potentials", potIdStr, mp);
info mp;
info update;

Note:
  • In Zoho CRM, the "Deals" module was formerly known as "Potentials" module.

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.  

Do check out other custom functions shared in this series.

Ciao! Stay tuned folks!


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.


Edit (5-May-2020):

Disclaimer: The code works when the quantity of products involved in the deal is 1. It sums up the unit price of the products added to the deal and updates in the Amount field. Sincere thanks to "Brian N." for pointing this out! For scenarios with product quantity greater than one, you might want to consider using the Quotes involved in the deal. Check this post for reference. Two scenarios are covered in that post. You might want to consider the value from the latest quote as requested by Bram Lyng Andersen or use the sum of all quote values associated with the respective deal. Use as you see fit and feel free to ask if you have any questions. 

    Access your files securely from anywhere









                          Zoho Developer Community




                                                • Desk Community Learning Series


                                                • Digest


                                                • Functions


                                                • Meetups


                                                • Kbase


                                                • Resources


                                                • Glossary


                                                • Desk Marketplace


                                                • MVP Corner


                                                • Word of the Day


                                                • Ask the Experts



                                                          • Sticky Posts

                                                          • Function #46: Auto-Calculate Sales Margin on a Quote

                                                            Welcome back everyone! Last week's function was about displaying the discount amount in words. This week, it's going to be about automatically calculating the sales margin for a particular quote, sales order or an invoice. Business scenario Where there is sales, there's also evaluation and competition between sales reps. A healthy rivalry helps to better motivate your employees to do smart work and close deals faster and more efficiently. But how does a sales rep get evaluated? 90% of the time, it's
                                                          • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

                                                            Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
                                                          • User Tips: Auto-Create Opportunity/Deal upon Quote Save (PART 1)

                                                            Problem: We use quotes which convert to sales orders but Users / Sales Reps do not create opportunities / deals and go straight to creating a quote. This leads to poor reporting. Implementing this solution improves reporting and makes it easier for users.
                                                          • Custom Function : Automatically send the Quote to the related contact

                                                            Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
                                                          • Function #50: Schedule Calls to records

                                                            Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM


                                                          Manage your brands on social media



                                                                Zoho TeamInbox Resources



                                                                    Zoho CRM Plus Resources

                                                                      Zoho Books Resources


                                                                        Zoho Subscriptions Resources

                                                                          Zoho Projects Resources


                                                                            Zoho Sprints Resources


                                                                              Qntrl Resources


                                                                                Zoho Creator Resources



                                                                                    Zoho CRM Resources

                                                                                    • CRM Community Learning Series

                                                                                      CRM Community Learning Series


                                                                                    • Kaizen

                                                                                      Kaizen

                                                                                    • Functions

                                                                                      Functions

                                                                                    • Meetups

                                                                                      Meetups

                                                                                    • Kbase

                                                                                      Kbase

                                                                                    • Resources

                                                                                      Resources

                                                                                    • Digest

                                                                                      Digest

                                                                                    • CRM Marketplace

                                                                                      CRM Marketplace

                                                                                    • MVP Corner

                                                                                      MVP Corner







                                                                                        Design. Discuss. Deliver.

                                                                                        Create visually engaging stories with Zoho Show.

                                                                                        Get Started Now


                                                                                          Zoho Show Resources

                                                                                            Zoho Writer

                                                                                            Get Started. Write Away!

                                                                                            Writer is a powerful online word processor, designed for collaborative work.

                                                                                              Zoho CRM コンテンツ






                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方




                                                                                                          • Recent Topics

                                                                                                          • We are looking for an experienced Zoho Developer

                                                                                                            Hi Everyone! We’re on the lookout for a skilled Zoho Developer with hands-on experience in the Zoho Developer Platform (The Vertical CRM Platform) and if you don't know what that is, then you are not the person we are looking for. You would also need
                                                                                                          • Initiate approval workflow after "on edit --> on success"

                                                                                                            Dear Community,  currently I am working on a initiative tracker which should handle approval workflows based on different initiative status. As far as I understand, an approval workflow can be triggered (only?) when data is entered for the input form to the database.  Example: A new initiative is created and submitted. --> Approval Workflow triggered Here comes my question: Is it also possible to trigger an approval workflow if the form was "simply" updated? (on edit --> on success) Imagine the initiative
                                                                                                          • Tax Deductible Donations to a Charity Organisation

                                                                                                            For Australia, what's the best/proper method for entering an expense that is a tax deductible donation to a charitable organisation. And thus is appears correctly in Accounts and BAS as a GST payable deduction?
                                                                                                          • Enhancing Zia's service with better contextual responses and article generation

                                                                                                            Hello everyone, We are enhancing Zia's Generative AI service to make your support experience smarter. Here's how: Increased accuracy with Qwen One of the key challenges in AI is delivering responses that are both contextually accurate and empathetic while
                                                                                                          • Simultaneous use of WhatsApp Account in SalesIQ and ZohoDesk

                                                                                                            Hi, We have only one number registered in Meta, it's possible use same account for two apps? All times here we try is stopping in SalesIQ. Regards,
                                                                                                          • External lookup fields to synchronise with Analytics

                                                                                                            Hello. I suggest adding external lookup custom fields to the Zoho Analytics integration settings. Currently, these types of fields are not available for synchronisation, so they cannot be used to generate reports with related tables in Analytics. Thank
                                                                                                          • Can we create Sprint with tasks from Multiple projects?

                                                                                                            Hi Team, We were using Zoho Sprints for quite sometime. Currently we have started the process of Sprint method. We couldnt create the active sprint board with the tasks from multiple projects. I would like to know whether this is possible or Any timeline
                                                                                                          • We should have an option to Toggle Off KB Article Links in AI Answer Bot Replies

                                                                                                            Hi everyone, I'm creating this topic to share a feature idea that I think would improve the customer experience when using the AI Answer Bot for self-service. The Current Behavior (The Problem) Currently, when the AI Answer Bot generates a summary or
                                                                                                          • Boot Loop After Removing Service from Client via Admin

                                                                                                            We have multiple laptops experiencing a boot loop / unable to login after the Zoho Remote service was removed from their machine remotely via the desktop client. The Windows sign-in screen is not available, and users are unable to login. This seems like
                                                                                                          • Request Backend Correction — Domains Mapped to Same Help Center (Multi-Brand Setup Failure)

                                                                                                            Hello Zoho Desk Support Team, I need assistance correcting a domain-to-brand mapping issue in our Zoho Desk instance (The Blue Ribbon Project). Both of our verified domains currently point to the same Help Center instead of separate brand portals. Current
                                                                                                          • is there any option to enable the participants interact - can write on the screen, while the screen is shared by the host?

                                                                                                            this is most expected features - for teaching children. is there any option to enable the participants interact - can write on the screen, while the screen is shared by the host?
                                                                                                          • How to disable the Login button in Desk Helpcenter

                                                                                                            Hey there, I'm testing out whether the help center within Zoho Desk could replace our existing Customer FAQ. I tried to customize the themes for the public help center frontend, but stumbled across the login button in the navigation bar. Is there any
                                                                                                          • Very long loading times | bad performance [ZOHO DC: EU]

                                                                                                            Hello there, we have recently noticed that the loading times have become extremely long when retrieving tickets and ticket details. For example, I open any ticket and get the following view. The subject and standard information (ticket owner, status etc.)
                                                                                                          • Client Portal ZOHO ONE

                                                                                                            Dear Zoho one is fantastic option for companies but it seems to me that it is still an aggregation of aps let me explain I have zoho books with client portal so client access their invoice then I have zoho project with client portal so they can access their project but not their invoice without another URL another LOGIN Are you planning in creating a beautiful UI portal for client so we can control access to client in one location to multiple aps at least unify project and invoice aps that would
                                                                                                          • Introducing the locking option for CRM records

                                                                                                            Last modified on 06/04/2023: Record locking option in CRM is now available for all Zoho CRM users in all DCs. Note that it was an early access feature available only upon request. Hello All, Hope you're doing well! We're thrilled to introduce our latest
                                                                                                          • Create custom rollup summary fields in Zoho CRM

                                                                                                            Hello everyone, In Zoho CRM, rollup summary fields have been essential tools for summarizing data across related records and enabling users to gain quick insights without having to jump across modules. Previously, only predefined summary functions were
                                                                                                          • Remembrance Day to Remember – Recalling Values

                                                                                                            The phrase “at the eleventh hour” refers to the 11th hour of the 11th day of the 11th month in 1918, when the hostilities of World War I came to an end—but it still holds meaning today. Remembrance Day (Veterans Day in the US) is observed on November
                                                                                                          • CRM x WorkDrive: File storage for new CRM signups is now powered by WorkDrive

                                                                                                            Availability Editions: All DCs: All Release plan: Released for new signups in all DCs. It will be enabled for existing users in a phased manner in the upcoming months. Help documentation: Documents in Zoho CRM Manage folders in Documents tab Manage files
                                                                                                          • Subforms in stateless forms

                                                                                                            I think the title says it all. We need to be able to add subforms to stateless forms. Currently the only workaround is to create a Form and delete each record upon submission of the form. I need to build an interface to update our inventory. Basically
                                                                                                          • Paste issues in ZOHO crm notes

                                                                                                            Hi, since a week or so I have issues with the paste function in ZOHO CRM. I use "notes" to copy paste texts from Outlook emails and since a week or so, the pasting doesnt function as it should: some text just disappears and it gives a lot of empty lines/enters.....
                                                                                                          • Standard Payment Term is not pulled from account to quotation

                                                                                                            Hey Team There seems to be something off. I do have "Net 30" as my default payment term in Zoho Books for my customers. If, from the customer overview or quote section, I create a new Quotation, the payment terms field stays blank and doesn't get the
                                                                                                          • Zoho Analytics Export API

                                                                                                            Hi Team, I’m working on some integration tasks and wanted to confirm if it’s possible to retrieve a Zoho Analytics table as JSON data using a Deluge script. I’ve already stored my custom data from multiple sources and combined it into a single source.
                                                                                                          • Best way to display complex Bookings Consultation Descriptions on Zoho Site?

                                                                                                            I am a new user so apologies if this has been asked before. I couldn't find any answers in the forum. We offer 18 complex Consultations to our subscribers. Our current platform lets me put detail on these Consultations thoroughly (200-300 words) during
                                                                                                          • Gmail is ramping up its email sender policy as of November 2025

                                                                                                            Hello marketers, As you may be aware, Gmail introduced a guideline for bulk senders starting February 2024. If not, here's a quick refresher straight from Google: After this policy was announced first in 2023 and soft-implemented in February 2024, we
                                                                                                          • Modifying iframe data of Zoho booking iframe

                                                                                                            Hello, I have integrated a Zoho Bookings embedded iframe into my website. Currently, I am pre-filling the booking form with default values as part of our process flow. However, I want to ensure that if an input field is already populated with a default
                                                                                                          • Zoho CRM Workflow and Function Backup Options

                                                                                                            Hi everyone! I have been able to make several backups of my CRM data and noticed that the Workflows and Functions are not included in these backups. To my knowledge, there is no backup feature for workflows and functions, which is problematic in of itself.
                                                                                                          • Enhance Sign CRM integration

                                                                                                            Hello all, I'm working on a custom Deluge script to enhance the integration between Zoho CRM and Sign by using a writer merge template for additional flexibility. I want to replicate the post-sign document integration that exists between CRM and Sign
                                                                                                          • YouTube Live streaming? how to? Zoom has this feature, built-in. Can't find it on zoho meetings.

                                                                                                            YouTube Live streaming? how to? Zoom has this feature, built-in. Can't find it on zoho meetings.
                                                                                                          • Is or will be possible to associate meeting transcription and summary, made by Zia, to meeting/contact/account record in CRM?

                                                                                                            Would be useful to keep context and track jobs, better if it will be auto
                                                                                                          • Zoho API to create ticket

                                                                                                            I'm developing an integration to create tickets via API, but, locally it works (send and recieve requests). In production it also works sending requests, but, my file don't recieve any response data. My URL is available in Zoho API Console and I have
                                                                                                          • Desk Field Not Showing in Analytics

                                                                                                            Hi there, I recently added a field to our Zoho Desk Ticket Information. I went and added the data retrospectively to the tickets. It is also marked as required, so all new tickets cannot be closed off without it being filled in. When I try to run a report
                                                                                                          • Export data using advanced export options and customizable settings

                                                                                                            Hello everyone, The user interface for exporting data has been revamped with updates to make data exports more flexible and efficient for users. These updates not only enhance usability but also bring advanced capabilities to help users extract precise
                                                                                                          • Retainer invoice in Zoho Finance modlue

                                                                                                            Hello, Is there a way of creating retainer invoices in the Zoho Finance module? If not can I request this is considered for future updates please.
                                                                                                          • Moving data from one pipeline to another

                                                                                                            Hey all, I've got some complex pipelines to build and I'd like to seperate them into seperate pipelines rather than have one mammoth one. If I create 2 pipelines, is there any easy way to use the output of Pipeline1 to be the input into Pipeline2? Or
                                                                                                          • How to export/find all deluge code.

                                                                                                            Hi, I have a large app wich contains several forms, reports, html views, I need to find thow my application if any contains specific word, I could find it manually by editing app and see on every section(field code, on succes, on load, etc) but I would like to do it faster. Is there a way to at least export it to a file the whole deluge code on my application?
                                                                                                          • Have Some Bugs in Zoho CRM Ask Zia Assistant

                                                                                                            Hi Support Team, I have found some bugs in Zoho CRM Ask Zia Feature Please Check below screenshot, insight option is showing twice i think its in early access that's why its have some bugs .
                                                                                                          • COD with Partial payment

                                                                                                            Two reasons why we need COD with partial payment option. 1) Since we deal heavy weight products our shipping costs are too high. If shipment is rejected by customer we incur huge loss. 2) Some competitors place fake orders with different names and return
                                                                                                          • Slicers are now available in Zoho Sheet—filter your data interactively

                                                                                                            At Zoho Sheet, we diligently track user requests and feedback. In line with this, based on extensive user requests, we've integrated Slicers to pivot tables and are delighted to announce its release. Slicers are interactive visual filters that have add,
                                                                                                          • Resizing a Record Template Background Inage

                                                                                                            Hi everyone, I have an issue which I can't seem to resolve: Basically, I'm designing a record template in certificate form. I've specified A5 landscape. I've set my background image the same dimensions with total pixels at 443,520. Whatever I try, when
                                                                                                          • Updated font library: New font styles and custom font options in Zoho Sheet

                                                                                                            Zoho Sheet's font library now supports 500+ font styles in 60+ languages! The updated font library is stacked with new font styles, and some of the previously available font styles have been replaced with equivalent options. There are two ways you can
                                                                                                          • Next Page