Create Purchase Orders for Individual Products instead of a Contact or Account, from a Sales Order.

Business scenario:

Working Capital is the life line of any business. Many components go into working capital and the most important one in the purview of sales and order fulfilment is the inventory. Maintaining your stocks at an optimal level helps keep your working capital in check. The vendor management side of CRM helps you do just that. In order to maintain an optimal level of inventory, it is essential to have your inventory, sales orders and purchase orders in sync. One way of achieving this is by maintaining optimal inventory level that fits your line of business and, replenish it as and when you get a new order. More importantly, this help you meet customer deadlines smoothly.

Assume your business deals with 2 products namely Product A and Product B, and say you fix the optimal inventory levels as 100 units each for Product A and Product B respectively. Your customer has just accepted your sales order for 5 units each for either of your products. The custom function I’m sharing today helps you issue PO’s instantly for 5 units of Product A to Vendor A and 5 units of Product B to Vendor B. This helps you maintain the inventory level of 100 units each for either of the products. You do this at the click of a button from inside your Sales Order. Easy?

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: "Purchase Orders for Products". 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());
productDet=ifnull(respMap.get("Product_Details"),"");
pdlist=List();
for each eachProd in productDet
{
productvalue = eachProd.get("product");
proid = productvalue.get("id");
proname = productvalue.get("name");
mp=map();
mp.put("product",{"name":proname,"id":proid});
mp.put("quantity",ifnull(eachProd.get("quantity"),"0").toLong());
mp.put("list_price",ifnull(eachProd.get("list_price"),"0.0").toDecimal());
mp.put(("discount"),ifnull(eachProd.get("discount"),"0.0").toDecimal());
mp.put("total",ifnull(eachProd.get("total"),"0.0").toDecimal());
mp.put("net_total",ifnull(eachProd.get("net_total"),"0.0").toDecimal());
pdlist.add(mp);
paramap=map();
paramap.put("Product_Details",pdlist);
paramap.put("Subject",ifnull(respMap.get("Subject"),""));
paramap.put("Contact_Name",ifnull(respMap.get("Contact_Name"),"").get("id"));
paramap.put("Account_Name",ifnull(respMap.get("Account_Name"),"").get("id"));
paramap.put("Owner",ifnull(respMap.get("Owner"),"").get("id"));
paramap.put("Sales_Order",ifnull(respMap.get("id"),""));
paramap.put("Tracking_Number",ifnull(respMap.get("SO_Number"),""));
paramap.put("Terms_and_Conditions",ifnull(respMap.get("Terms_and_Conditions"),""));
paramap.put("Description",ifnull(respMap.get("Description"),""));
paramap.put("Shipping_Cuty",ifnull(respMap.get("Shipping_Cuty"),""));
paramap.put("Shipping_Code",ifnull(respMap.get("Shipping_Code"),""));
paramap.put("Shipping_Method",ifnull(respMap.get("Shipping_Method"),""));
paramap.put("Shipping_State",ifnull(respMap.get("Shipping_State"),""));
paramap.put("Shipping_Street",ifnull(respMap.get("Shipping_Street"),""));
paramap.put("Status",ifnull(respMap.get("Status"),""));
createResp = zoho.crm.create("Purchase_Orders", paramap);
info paramap;
info createResp;
}
return "success";

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