Create Quotes from deals with just the click of a button

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 function:

  • Go to Setup > Customization > Modules and Fields > Deals > Links and Buttons > + New Button.
  • Provide a name for the button. For example: "Create Quote from deal".
    ​Add a description(optional).
  • Select the placement of the button as View Page.
  • Select the action to be performed as "Writing function".
  • Copy the code given below.
  • Click "Edit arguments".
  • Enter the name as "potId" and select the value as "Deal Id".
  • Replace 'xxxxxxxx' with your orgID.
  • Click Save & Execute Script.
  • Save the changes.
  • Select the profiles who can view this button.
  • Click Save.

The Code:


potDetails = zoho.crm.getRecordById("Deals",potId.toLong());
quotesubject = ifnull(potDetails.get("Deal_Name"),"");
contact = ifnull(potDetails.get("Contact_Name").get("id"),"");
account = ifnull(potDetails.get("Account_Name").get("id"),"");
description = ifnull(potDetails.get("Description"),"");
RelatedProducts = zoho.crm.getRelatedRecords("Products","Deals",potId.toLong());
product_items = List();
sub = 0.0;
for each product in RelatedProducts
{
proid = product.get("id");
proname = product.get("Product_Name");
productDesc= ifnull(product.get("Description"),"Manque Description Produit !!!");
quantity = 1;
price = ifnull(product.get("Unit_Price"),"0.0").toDecimal();
listprice = price * quantity;
lineitem = Map();
lineitem.put("product",{"name":proname,"id":proid});
lineitem.put("product_description",productDesc);
lineitem.put("quantity",quantity);
lineitem.put("net_total",listprice);
lineitem.put("total",listprice);
lineitem.put("list_price",listprice);
sub = sub + listprice;
product_items.add(lineitem);
}
paramap = Map();
paramap.put("Product_Details",product_items);
paramap.put("Subject",quotesubject);
paramap.put("Contact_Name",contact);
paramap.put("Account_Name",account);
paramap.put("Deal_Name",potId.toLong());
paramap.put("Description",description);
createResp = zoho.crm.createRecord("Quotes", paramap);
info paramap;
info createResp;
newid = createResp.get("id");
openUrl("https://crm.zoho.com/crm/orgxxxxxxxx/tab/Quotes/" + newid, "same window");
return "Success";

 

Note:

  • The code is zoho.crm._getRecordById for Version 1.0 of APIs and it is zoho.crm.getRecordById for V2 APIs.
     

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!

Return to Tips