Keeping 'deals' in sync with sales orders in Zoho Inventory

Keeping 'deals' in sync with sales orders in Zoho Inventory

Hey all,

I have a function that generates a sales order in Zoho Inventory when a deal is created in Zoho CRM.

I'd like to implement a function (or solution) that keeps them both 'in sync' after creation, trigged by an edit of the line items in either the deal (which would update the sales order) or the sales order (which would update the deal).

I've attempted a few functions but am not having any success. Any help would be amazing. Thanks!

This is the CRM Function.
  1. organization_id = "xxxxxxxx";
  2. order = zoho.crm.getRecordById("Deals",oID);
  3. soid = order.get("Sales_Order_ID");
  4. filter = Map();
  5. filter.put("salesorder_id",soid);
  6. saleso = zoho.inventory.getRecords("Salesorders",organization_id,filter,"xxxxxxxx");
  7. product_details = order.get("Order_Details");
  8. sales_map = Map();
  9. product_list = List();
  10. for each  product in product_details
  11. {
  12. sales_map = Map();
  13. product_entry = product.get("Product_Name");
  14. product_item_name = product_entry.get("name");
  15. product_item_quantity = product.get("Qty");
  16. product_item_total = product.get("Unit_Price_1");
  17. sales_map.put("name",product_item_name);
  18. sales_map.put("rate",product_item_total);
  19. sales_map.put("quantity",product_item_quantity);
  20. product_list.add(sales_map);
  21. }
  22. info product_list;
  23. inventory_map = Map();
  24. inventory_map.put("line_items",product_list);
  25. update_entry = zoho.inventory.updateRecord("Salesorders",organization_id,soid,inventory_map,"xxxxxxxxx");

This is the Inventory Function
  1. salesorderID = salesorder.get("salesorder_id");
  2. organization_id = "xxxxxxxx";
  3. crmid = salesorder.get("zcrm_potential_id");
  4. info crmid;
  5. dealid = Map();
  6. dealid.put("deal_id",crmid);
  7. deal = zoho.crm.getRecords("Deals",1,1,dealid,"xxxxxxxxx");
  8. product_details = salesorder.get("Order_Details");
  9. sales_map = Map();
  10. product_list = List();
  11. for each  product in product_details
  12. {
  13. sales_map = Map();
  14. product_entry = product.get("group_name");
  15. product_item_name = product_entry.get("name");
  16. product_item_quantity = product.get("quantity");
  17. product_item_total = product.get("rate");
  18. //info product_item_description;
  19. sales_map.put("name",product_item_name);
  20. sales_map.put("Unit_Price_1",product_item_total);
  21. sales_map.put("Qty",product_item_quantity);
  22. product_list.add(sales_map);
  23. }
  24. info product_list;
  25. inventory_map = Map();
  26. inventory_map.put("Order_Details",product_list);
  27. update_entry = zoho.crm.updateRecord("Deals",organization_id,dealid,inventory_map,"xxxxxxxxxxx");