Create purchase orders from sales orders at just the click of a button.

Business scenario:

Inventory control is an integral part of any order fulfilment process. Unless you have the required inventory, you’d not be able to fulfil your deals on time. The logical next step once your customer accepts your Estimate/Quote is to issue a Sales Order. At this stage, if you don’t have the required items or, if you are a reseller or a distributor who places an order to another vendor to fulfil the deal, you’d have to issue a corresponding Purchase Order. Based on the nature of the deal, the information in your purchase order may vary and entering the details manually is a major hassle that's best avoided if possible. That's exactly this week's custom functions helps us with.

This week's custom function can be embedded to a button, that gets placed either inside the Sales Order module or inside a record in the Sales Order module. Upon the click of the button, a Purchase Order gets created with all the details from the Sales order. Don't worry, it's just a one-time thing. :)

Getting started with the function:

  1. Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
  2. Provide a name for the button. For example: "[The Purchase Order name or The Product's name]". Add a description(optional).
  3. Select the placement of the button as View page.
  4. Select the action to be performed as "Writing function".
  5. Copy the code given below.
  6. Click "Edit arguments".
  7. Enter the name as "soId" and select the value as "Sales Order Id".
  8. Click Save & Execute Script.
  9. Save the changes.
  10. Select the profiles who can view this button.
  11. Click Save.

The code:

For v2 Editor - DRE:

respMap = zoho.crm.getRecordById("Sales_Orders", input.soId.toLong());
for each eachProd in productDet
productvalue = eachProd.get("product");
proid = productvalue.get("id");
proname = productvalue.get("name");
createResp = zoho.crm.create("Purchase_Orders", paramap);
info createResp;
return "success";


  • This function code works only when you have the latest version of Zoho CRM's APIs.

Found this useful? Try it out and let us 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