Function-5: Create Quotes from deals with just the click of a button!

Function-5: Create Quotes from deals with just the click of a button!

Welcome back everyone!

Last week, we learnt about how to get the total taxes, total quantity and total discounts for a customer at a glance. This week, let's look at a custom function that makes your deals proceed smoother by creating a one-click-Quote directly from the deal.

Business scenario:

You hit a stage in a deal when you know it would follow through. This is when you must create a Quote. which is a legal agreement between a prospect and a vendor. Wouldn't it be cool to add a button to the deals module to automatically create a Quote from within the deal, on just a click of a button? Create a Quote at any stage of the deal and associate with the Quote, and save time!

Besides, the quote has the product details specific to the deal, leading to a simultaneously updated inventory as well. Two birds with one stone and all that :)

Getting started with the custom function:
  1. Go to Setup > Customization > Modules > Deals > Links and buttons >Create new button .
  2. Provide a name for the button. For example: “Create Quote from deal”. Add a description(optional).
  3. Select the placement of the button as View page .
  4. Select the action to be performed as " Writing custom function ".
  5. Click “ Free flow scripting ”.
  6. Copy the code given below.
  7. Click “ Edit arguments ”.
  8. Enter the name as “ potIdStr ” and select the value as “ Potential Id ”.
  9. Save the changes.
The script:

Code for Version 2.0 API:

  1. potDetails = zoho.crm.getRecordById("Deals",potIdStr.toLong());
  2. paramap = Map();
  3. if( ifnull(potDetails.get("Contact_Name"),"") != "")
  4. {
  5. contact = ifnull(potDetails.get("Contact_Name").get("id"),"");
  6. paramap.put("Contact_Name",contact);
  7. }
  8. if( ifnull(potDetails.get("Account_Name"),"") != "")
  9. {
  10. account = ifnull(potDetails.get("Account_Name").get("id"),"");
  11. paramap.put("Account_Name",account);
  12. }
  13. RelatedProducts = zoho.crm.getRelatedRecords("Products","Deals",potIdStr.toLong());
  14. product_items = List();
  15. for each product in RelatedProducts
  16. {
  17. proid = product.get("id");
  18. proname = product.get("Product_Name");
  19. productDesc= ifnull(product.get("Description"),"Manque Description Produit !!!");
  20. quantity = 1;
  21. price = ifnull(product.get("Unit_Price"),"0.0").toDecimal();
  22. listprice = price * quantity;
  23. lineitem = Map();
  24. lineitem.put("product",{"name":proname,"id":proid});
  25. lineitem.put("product_description",productDesc);
  26. lineitem.put("quantity",quantity);
  27. lineitem.put("net_total",listprice);
  28. lineitem.put("total",listprice);
  29. lineitem.put("list_price",listprice);
  30. product_items.add(lineitem);
  31. }
  32. paramap.put("Product_Details",product_items);
  33. paramap.put("Subject",ifnull(potDetails.get("Deal_Name"),""));
  34. paramap.put("Deal_Name",potIdStr.toLong());
  35. paramap.put("Description",ifnull(potDetails.get("Description"),""));
  36. createResp = zoho.crm.createRecord("Quotes", paramap);
  37. info paramap;
  38. info createResp;
  39. newid = ifnull(createResp.get("id"),"");
  40. if ( newid != "")
  41. {
  42. openUrl( "https://crm.zoho.com/crm/EntityInfo.do?module=Quotes&id=" + newid, "same window");
  43. return "New Quote created successfuly";
  44. }
  45. else
  46. {
  47. return "Quote could not be created. Missing product details in Deal.";
  48. }
Code for Version 1.0 API:

potIdStr = input.potId.toString();
potDetails = zoho.crm.getRecordById("Potentials", input.potId.toLong());
RelatedProducts = zoho.crm.getRelatedRecords("Products", "Potentials", potIdStr);
quotesubject = ifnull(potDetails.get("Potential Name"),"");
contact = ifnull(potDetails.get("CONTACTID"),"");
account = ifnull(potDetails.get("ACCOUNTID"),"");
description = ifnull(potDetails.get("Description"),"");
pdlist = List();
sub = 0.0;
for each eachProd in RelatedProducts
{
productDesc = ifnull(eachProd.get("Product Description"),"");
quantity = 1;
productId = ifnull(eachProd.get("PRODUCTID"),"");
price = (ifnull(eachProd.get("Unit Price"),"0.0")).toDecimal();
listprice = (price * quantity);
mp = map();
mp.put("Product Id", productId);
mp.put("Quantity", quantity);
mp.put("List Price", listprice);
mp.put("Net Total", listprice);
pdlist.add(mp);
sub = (sub + listprice);
}
paramap = map();
paramap.put("Products", pdlist);
paramap.put("Subject", quotesubject);
paramap.put("CONTACTID", contact);
paramap.put("ACCOUNTID", account);
paramap.put("POTENTIALID", input. potId);
paramap.put("Description", description);
paramap.put("Sub Total", sub);
paramap.put("Grand Total", sub);
createResp = zoho.crm.create("Quotes", paramap);
info createResp;
newid = createResp.get("Id");
return "Quote Created";

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. See you all next week with another interesting custom function. Ciao!

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.


Edited on 18-May-2020:
  • As Contact and Account names are not mandatory, the code has been updated with a null check to skip them when they are empty, and update them in the Quote when available.

  • Product field cannot be empty while creating quotes. This code fetches the product details from the Deal and if the code is executed on a Deal record with empty product field, it will prompt the user to check the same.

  • As of now, the product quantity is taken as one in product field of Deals. This is a system limitation, and if your sale involves a quantity greater than one, you will have to update it manually in the newly created quote. The Quote opens in a new tab immediately upon creation.

    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      • 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
      • 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,
      • Function-2: Round-Robin assignment of records

        Welcome back folks! Last week, we saw how to update sales commission in quotes using a custom function. This week, let's see an interesting use case asked by many of you - auto-assignment records by round-robin method. Business scenario: Right now, the solution allows you to auto-assign leads from web form and imported lists. Let us look at a need where you want to auto-assign leads from in-bound calls in a round-robin method, across modules. Prerequisite: You must create a permanent record in the

      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

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

                            Zoho CRM コンテンツ




                              ご検討中の方