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

                                                          • 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
                                                          • Function #37: Create a Purchase Order from a Quote

                                                            Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,


                                                          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 Writer

                                                                                            Get Started. Write Away!

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

                                                                                              Zoho CRM コンテンツ



                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方




                                                                                                          • Recent Topics

                                                                                                          • In arattai received message can't be deleted

                                                                                                            The issue has been noticed in following: arattai app (Android) arattai app (Window) arattai web While the message posted by me may be deleted, the ones received from others can't be. The item <Delete> change to <Report> when the message is a received
                                                                                                          • Show/ hide specific field based on user

                                                                                                            Can someone please help me with a client script to achieve the following? I've already tried a couple of different scripts I've found on here (updating to match my details etc...) but none of them seem to work. No errors flagged in the codes, it just
                                                                                                          • Zoho sheet for desktop

                                                                                                            Hi is zoho sheets available for desktop version for windows
                                                                                                          • Guided Conversations - Ticket Creation

                                                                                                            Hi there, Using Guided Conversations to Take Customer Data and apply it into a Support Ticket for internal use, Is there a way to take multiple Textual Variables Inputs (A series of questions), and have the answers all appear in the Description of the
                                                                                                          • Edit 'my' Notes only

                                                                                                            The permissions around Notes should be more granular, and allow to user to be able to edit the notes he created only. The edit Notes permission is useful as it allows the user to correct any mistakes or add information as needed. However, with this same
                                                                                                          • Sales Order, Invoice and Payment numbers

                                                                                                            Hi zoho friends, it is me again, the slow learner. I'm wondering if there is a way to have it so the Sales order, invoice and payment numbers are all the same? It would be easier for me if they were the same number so there is not so many reference numbers
                                                                                                          • Migrate file from Single File Upload to Multi File Upload

                                                                                                            Dears, I have created a new field Multi File Upload to replace the old Single File Upload field. I'd like to ask you guys what is the best way to migrate the files to the new field?
                                                                                                          • Where are Kanban swimlanes

                                                                                                            So i've been playing with Zoho Projects Kanban view a bit more. It appears that task lists are being used as the Kanban columns, which makes sense from the implementation point of view but not the logical one.  Kanban columns are statuses that a task can flow through, while a task list has been a logical way to organize related tasks and relate them to a mislestone. In other words a task in a particular task can go through several stages while remaining in the same task list. After doing some research
                                                                                                          • Is anyone else having trouble saving a custom image in their email signature, or is it just me?

                                                                                                            When I try to save the image I get an error that says "Operation Failed" I opened a support ticket two weeks ago and received a response that it would be debugged, but it still isn’t working
                                                                                                          • Tip 19: How to display images in Pages using ZML snippets

                                                                                                            Hi folks, We're back with another tip on how to use Zoho Markup Language (ZML) to create interactive pages in Zoho Creator. You can use ZML snippets to add various kinds of components to your pages and structure them in meaningful ways. That's not all, though—using ZML you can ensure your application is automatically compatible with all kinds of devices without any inconsistencies. We often get questions from users about how to invoke Deluge scripts within ZML code. Here's a simple use case for adding
                                                                                                          • Can zoho swign format block text spacing automatically when prefilled from zoho crm?

                                                                                                            I'm sending zoho sign template from zoho crm, so that zoho crm pre-populates most fields. I have existing pdf documents that i am having signed. I have no ability to change the pdf documents, they are standardized government forms. The problem I am facing
                                                                                                          • Forced Logouts - Daily and More Frequent

                                                                                                            In the last month or so, I've been getting "power logged out" of all of my Zoho apps at least daily, sometimes more frequently. This happens in the same browser session on the same computer, and I need to re-login to each app separately after this happens.
                                                                                                          • Zoho Inventory / Finance Suite - Add feature to prevent duplicate values in Item Unit field

                                                                                                            I've noticed that a client has 2 values the same in the Unit field on edit/create Items. This surprised me as why would you have 2 units with the same name. Please consider adding a feature which prevents this as it seems to serve no purpose.
                                                                                                          • Reference lookup field values in Client script

                                                                                                            hello all, I'm using a "ZDK.Apps.CRM.Products.searchByCriteria" function call, which is returning the matching records correctly; however, one of the fields is a lookup field which I need the associated data. I believe there is a way to get this data
                                                                                                          • Open "Live Chat" from a hyperlink?

                                                                                                            Hi, I often write paragraphs and text on our company website, and usually say you can get in touch with us via live chat. Can the chat window be triggered to pop open without clicking the chat graphic in the bottom window, and use it in a hyperlink? ie:
                                                                                                          • Zoho Analytics - Make text clickable in underlying data

                                                                                                            Hi Community, I have a simple sales report based on a Invoice query table. I have included a link on to each invoice on the table and sent the Invoice number URL to the link. This works find in the query table, but when I click underlying data on the
                                                                                                          • In App Auto Refresh/Update Features

                                                                                                            Hi,    I am trying to use Zoho Creator for Restaurant management. While using the android apps, I reliased the apps would not auto refresh if there is new entries i.e new kitchen order ticket (KOT) from other users.   The apps does received notification but would not auto refresh, users required to refresh the apps manually in order to see the new KOT in the apps.    I am wondering why this features is not implemented? Or is this feature being considered to be implemented in the future? With the
                                                                                                          • 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
                                                                                                          • Every time an event is updated, all participants receive an update email. How can I deactivate this?

                                                                                                            Every time an event is updated in Zoho CRM (e.g. change description, link to Lead) every participant of this meeting gets an update email. Another customer noticed this problem years ago in the Japanese community: https://help.zoho.com/portal/ja/community/topic/any-time-an-event-is-updated-on-zohocrm-calendar-it-sends-multiple-invites-to-the-participants-how-do-i-stop-that-from-happening
                                                                                                          • Is there a way to show contact emails in the Account?

                                                                                                            I know I can see the emails I have sent and received on a Contact detail view, but I want to be able to see all the emails that have been sent and received between all an Accounts Contacts on the Account Detail view. That way when I see the Account detail
                                                                                                          • Online Assessment or any aptitude test

                                                                                                            This video is really helpful! I have one question — if I share an assessment form link (through email or with the application form on my career page), how does Zoho Recruit evaluate it? Can a candidate use Google or external help while taking the test,
                                                                                                          • How can I filter a field integration?

                                                                                                            Hi,  I have a field integration from CRM "Products" in a form, and I have three product Categories in CRM. I only need to see Products of a category. Thanks for you answers.
                                                                                                          • Email task creator when task is updated/marked complete

                                                                                                            I am looking for a way to notify the creator of a task in zoho todo when - Task is updated Task is closed Comments entered 1 and 2 are critical, and I cannot find a zoho flow to do this. There is no way that as a manager I will know when someone has completed
                                                                                                          • How to move emails to Shared Mailbox?

                                                                                                            Hello, I created a Shred Mailbox instead of using a distribution group. But I cannot move previous emails to certain shared mailbox. Is it possible move some emails from inbox to shared mailbox?
                                                                                                          • How to implement new online payment gateway?

                                                                                                            Hello, Can you tell me how to proceed to implement my local payment gateway? DIBS has an open avaiable API that should be easy to implement into ZOHO BOOKS. http://tech.dibspayment.com/dibs_payment_window
                                                                                                          • Zoho CRM - Portal Users Edit Their Own Account Information

                                                                                                            Hi Community, I'm working on a client portal and it seems like the only I can make the Account record editable to the Contact, is if I add another lookup on the Account to the Contact record. Am I missing something as the account already has a list of
                                                                                                          • I’ve noticed that Zoho Sheet currently doesn’t have a feature similar to the QUERY formula in Google Sheets or Power Query in Microsoft Excel.

                                                                                                            These tools are extremely helpful for: Filtering and extracting data using simple SQL-like queries Combining or transforming data from multiple sheets or tables Creating dynamic reports without using complex formulas Having a Query-like function in Zoho
                                                                                                          • Connecting Zoho Mail with Apollo.io

                                                                                                            Hi, I am trying to connect my Zoho Mail account with my Apollo.io account to start sending cold email for prospecting purposes. I have activated the IMAP setting but I am still unable to connect to the Apollo account. I am using my email credentials but
                                                                                                          • Where does this report come from in the Zoho One ecosystems?

                                                                                                            Is this directly from MA, Analytics or ??? ???
                                                                                                          • Job Alerts for Candidates

                                                                                                            hi All, I have 2 questions relating to sharing job details with candidates. 1. is there a way to notify candidates that meet certain criteria of current jobs available? eg. I run a candidate search, and identify 50 candidates that might be suitable. Can
                                                                                                          • Contact's title in "Contact Role Mapping"

                                                                                                            When I'm creating a deal, I'd like to see the contacts title in the listing. Right now, I only see this: How can I get the contact's title in there?
                                                                                                          • Zoho CRM - Client Portal - Hide Notes Related List

                                                                                                            Hi Community, I'm building a customer portal and I can't find a way to hide the notes related list. I don't want the client to see the notes I have about them. Is there a way to do this as it is no bin/trash icon when I hover over.
                                                                                                          • "Pivot Table" Conditional Formatting

                                                                                                            Team, I there a way to use conditional formatting a "Pivot Table"  report? Thanks, Arron Blue Pumpkin Hosting | Solutions Made Simple
                                                                                                          • How many clients can be added to Zoho Practice?

                                                                                                            How many clients can be added to Zoho Practice without having their zoho app?
                                                                                                          • Stage History

                                                                                                            when viewing a ticket , and you look at stage history tab (kanban view) and look at the stage duration column in days, it shows the current stage of the ticket as " current stage ". Should it not rather show the amount of days it has been in that current
                                                                                                          • Enhancements to finance suite integrations

                                                                                                            Update: Based on your feedback, we’ve updated the capabilities for integration users. In addition to the Estimates module, they can now create, view, and edit records in all the finance modules including Sales Order, Invoices, Purchase Order. We're also
                                                                                                          • Send Automated WhatsApp Messages and Leverage the Improved WhatsApp Templates

                                                                                                            Greetings, I hope all of you are doing well. We're excited to announce a major upgrade to Bigin's WhatsApp integration that brings more flexibility, interactivity, and automation to your customer messaging. WhatsApp message automation You can now use
                                                                                                          • Automating Ticket Responses Using Zoho Desk's AI Features

                                                                                                            We’re looking to set up an automation within Zoho Desk that can analyze incoming emails or tickets and automatically respond with relevant knowledge base articles based on the content of the request. Could you please guide us on how to configure this
                                                                                                          • Optimising CRM-Projects workflows to manage requests, using Forms as an intermediary

                                                                                                            Is it possible to create a workflow between three apps with traceability between them all? We send information from Zoho CRM Deals over to Zoho Projects for project management and execution. We have used a lookup of sorts to create tasks in the past,
                                                                                                          • Service locations are tied to contacts?

                                                                                                            Trying the system out. And what I discovered is that it seems that the whole logic of the app is, I'd say, backwards. There is a Customer - a company. The company has contact persons and service locations can be associated with different contact persons.
                                                                                                          • Next Page