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.

    • Sticky Posts

    • 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-1: Compute and update sales commission in quotes.

        Welcome back folks! In this week's custom functions series, we've picked a requirement that has often been asked by users! Business requirement: In most sales organizations, commissions are an integral part of the extrinsic rewards program, contributing significantly to the sales person’s compensation package. Sales commission is usually calculated as a percentage of revenue generated by the sales person. What if your sales team is enabled with an option to check their sales commission associated
    • 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 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 : Updating Lead Score.

      Scenario: Updating Lead Score. You may want to rank the leads in your CRM account in order to determine their sales-readiness. The scoring can be based on certain predefined values. This lead scoring can be done with custom functions. You can have a custom field for the Score and use custom functions to update the Lead Score based on certain values. When you update the fields in leads, the score will be updated automatically.   This custom function can also be used for other modules by making small

            Zoho DataPrep Resources


                Zoho CRM Plus Resources

                  Zoho Books Resources


                    Zoho Subscriptions Resources

                      Zoho Desk Resources

                        Zoho Projects Resources


                          Zoho Sprints Resources


                            Zoho Orchestly Resources


                              Zoho Creator Resources


                                Zoho WorkDrive Resources




                                    Zoho Campaigns Resources

                                      Zoho CRM Resources

                                                  Design. Discuss. Deliver.

                                                  Create visually engaging stories with Zoho Show.

                                                  Get Started Now




                                                      Zoho Writer Writer

                                                      Get Started. Write Away!

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