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

                                                                                                          • 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
                                                                                                          • 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
                                                                                                          • Introducing Data Bars: Graphically represent changes in data within the cells

                                                                                                            Conditional formatting has helped millions of spreadsheet users analyze and highlight their data more efficiently. In addition to the classic rules, color scales, and icon sets available in Zoho Sheet, you can now apply Data Bars, a convenient method
                                                                                                          • Default Font Size in Desk

                                                                                                            How do I set my default font size in Desk? It takes me about 45 minutes to find the place to set it, then, when I sign out of Zoho and log back in, it's back to font 10 again. Seems like this would be simple, but like everything with Zoho, it's buried
                                                                                                          • Tip #19 - Create checkbox tracker in your spreadsheet

                                                                                                            Hello Sheet users! We are here with yet another tip to help you get the most out of Zoho Sheet. Spreadsheets can be used to handle a variety of tasks, but ever tried using checkboxes to track the progress of your action items dynamically? Here's a sample
                                                                                                          • Tip #20 - Three things you probably didn't know you can do with picklists

                                                                                                            Hello Zoho Sheet users! We’re back with another quick tip to help you make your spreadsheets smarter. Picklists are a great tool to maintain consistency in your spreadsheet. Manually entering data is time-consuming and often leaves typos and irregular
                                                                                                          • Per Level Approval for admins

                                                                                                            We need Process admins like Zoho CRM in Zoho Books for per stage approval Currently in books, admins only have the option for Final Approval But for example, in cases like when an employee is on leave, we can't just approval one level we only have option
                                                                                                          • CUSTOM FUNCTION GIVE ERROR #EVAL!

                                                                                                            CUSTEM FUNCTION CREATE KYA ZOHOSHEET ME US FUNCTION KO USE KIYA LEKIN DATA TO SAHI HAI LAKIN DATA SHEET ME NAHI LAG LAHA HAI KRUPYA SOLVE KARE MY CODE IS float ADDTWO_TWO(float NO1, float NO2) { ADD = NO1 + NO2; return ADD; }
                                                                                                          • Need to set workflow or journey wait time (time delay) in minutes, not hours

                                                                                                            Minimum wait time for both Campaigns workflows and Marketing Automation journeys is one hour. I need one or the other to be set to several minutes (fraction of the hour). I tried to solve this by entering a fraction but the wait time data type is an integer
                                                                                                          • Integrate Projects for Desk KB article release tasks

                                                                                                            Could you please look into the possibility of integrating project tasks for Zoho Desk article release processes? We are looking for an internal integration between Zoho Projects and Zoho Desk's KB article drafting, reviewing and releasing tasks. We could
                                                                                                          • Feature enhancement: Highlight rows based on a cell value

                                                                                                            Hello Sheet users, We're excited to announce a new feature enhacement, shaped directly by your valuable feedback! As you might know, conditional formatting is a great tool for anyone dealing with large data sets. Previously, if you’ve ever wanted to draw
                                                                                                          • Shortcut to fill a range of cells

                                                                                                            Good evening: I'm writing because I haven't been able to find a feature that allows you to select a range of cells, type in one of them, and then use a key combination to type in all of them. In Excel, the keyboard shortcut is Ctrl+Enter. I haven't found
                                                                                                          • Detect and ignore bots in visitors

                                                                                                            The SalesIQ visitor numbers are basically useless to us because there is no bot detection. We get the same bots coming in from the same countries looking at the same pages every day. It can't be that difficult to tell the difference between an actual
                                                                                                          • Updating custom fields in Zoho Projects

                                                                                                            Hi I am wondering if anyone has experience with custom fields in Zoho Projects. I am struggling to update the field using either deluge or the api endpoint. My code is: //custom_Map = map(); custom_Map = {"UDF_DOUBLE_1":"0.27"}; update_Map = map(); update_Map.put("custom_fields",custom_Map.toList());
                                                                                                          • Markdown for Desk?

                                                                                                            Hi, my company wants to use markdown for formatting text in Desk (in all modules there, especially Tickets and Helpcenter). Zoho already offers use of markdown in several products (see https://help.zoho.com/portal/en/kb/backstage/microsite-guide/formatting-with-markdown/articles/formatting-with-markdo)
                                                                                                          • Change Currency symbol

                                                                                                            I would like to change the way our currency displays when printed on quotes, invoices and purchase orders. Currently, we have Australian Dollars AUD as our Home Currency. The only two symbol choices available for this currency are "AU $" or "AUD". I would
                                                                                                          • Calendar not working

                                                                                                            Are we the only ones. On any browser we cannot click on any of our calendar appointments and get them to open. They just make the browser loop. WE have reached out and have been told they are working on it. The office staff are really stuck. The point
                                                                                                          • Good news! Calendar in Zoho CRM gets a face lift

                                                                                                            Dear Customers, We are delighted to unveil the revamped calendar UI in Zoho CRM. With a complete visual overhaul aligned with CRM for Everyone, the calendar now offers a more intuitive and flexible scheduling experience. What’s new? Distinguish activities
                                                                                                          • Tip of the week #16 - Search and filter threads based on criteria

                                                                                                            Zoho TeamInbox lets you search and filter threads with any information that you have about the thread. You just have to input the criteria and Zoho TeamInbox will list all the threads that match the condition.   Firstly, there is a global search you can
                                                                                                          • WhatsApp Message Template Quick Reply Buttons

                                                                                                            Hello, I created my first Message Template to overcome the 24-hr messaging window and it was approved by WhatsApp/Meta. When I go to Meta, I also see that template brought from Zoho Desk, and used it via Zoho Desk IM. However, I notice that when in Meta's
                                                                                                          • Account in Quick View Filter

                                                                                                            I have a report that I often run against a specific Account. Every time, I have to go into the edit menu and change the Advanced Filter. I would prefer to use the Quick View Filter, but it does not allow me to use the one and only field that makes any
                                                                                                          • All new Address Field in Zoho CRM: maintain structured and accurate address inputs

                                                                                                            The address field will be available exclusively for IN DC users. We'll keep you updated on the DC-specific rollout soon. It's currently available for all new sign-ups and for existing Zoho CRM orgs which are in the Professional edition. Latest update
                                                                                                          • Collapsible Sections & Section Navigation Needed

                                                                                                            The flexibility of Zoho CRM has expanded greatly in the last few years, to the point that a leads module is now permissible to contain up to 350 fields. We don't use that many, but we are using 168 fields which are broken apart into 18 different sections.
                                                                                                          • Set Display for Numbers/Currency/etc with Client Script/Customization in Canvas List Page

                                                                                                            Is it possible to set a display mask for a number/currency field using Client Script or customization? I have custom fields that I would like to keep the decimal places for calculation purposes, but do not need them displayed to the user. So 101.3568
                                                                                                          • 136.143.188.51 blocked by spamcop

                                                                                                            Zoho mailserver seems to be blocked by spamcop. Cant send mail to my customer. Not sure what to do.
                                                                                                          • 🚀 WorkDrive 5.0: Evolving from a file sharing app to an intelligent content management platform: Phase 2

                                                                                                            Hello everyone, WorkDrive's primary focus has always been to provide an intelligent and secure content management platform, simplify collaboration, and be the central repository of files for all Zoho apps. In our previous announcement, we unveiled the
                                                                                                          • Sync desktop folders instantly with WorkDrive TrueSync (Beta)

                                                                                                            Keeping your important files backed up and accessible has never been easier! With WorkDrive desktop app (TrueSync), you can now automatically sync specific desktop folders to WorkDrive Web, ensuring seamless, real-time updates across devices. Important:
                                                                                                          • i keep see there is a connetion issue connecting 3rd party api on zoho when using zia

                                                                                                            hi there , i have set up open ai api to zoho zia (copied and pasted to zoho zia) but I keep getting notificaiton "there is a connetion issue connecting 3rd party api on zoho" when using zia on top when click zia and try to type in word there
                                                                                                          • Time Entries in Analytics

                                                                                                            I am trying to import a zoho sheet into zoho analytics. In my sheets one of the columns has "time Entries" in this "format HH:MM am/pm" example 11:00 PM. After import, i noticed that analytics converted the time to "00 Jan 1900 23:00:00".. how do i maintain
                                                                                                          • Deleting Fields in CRM Deletes Views in Analytics

                                                                                                            Hey friends! I'm having some issues when we modify some fields within ZohoCRM. There are times where we need to sunset a field and eventually completely remove it. In these instances, it seems like a lot of views are removed in Analytics. This ranges
                                                                                                          • Booking outside of scheduled availability

                                                                                                            Is there a way for staff (such as the secretary) to book appointments outside of the scheduled availability? Right now to do this special hours must be set each time. There should be a quicker way. Am I missing something?
                                                                                                          • Next Page