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.
- organization_id = "xxxxxxxx";
- order = zoho.crm.getRecordById("Deals",oID);
- soid = order.get("Sales_Order_ID");
- filter = Map();
- filter.put("salesorder_id",soid);
- saleso = zoho.inventory.getRecords("Salesorders",organization_id,filter,"xxxxxxxx");
- product_details = order.get("Order_Details");
- sales_map = Map();
- product_list = List();
- for each product in product_details
- {
- sales_map = Map();
- product_entry = product.get("Product_Name");
- product_item_name = product_entry.get("name");
- product_item_quantity = product.get("Qty");
- product_item_total = product.get("Unit_Price_1");
- sales_map.put("name",product_item_name);
- sales_map.put("rate",product_item_total);
- sales_map.put("quantity",product_item_quantity);
- product_list.add(sales_map);
- }
- info product_list;
- inventory_map = Map();
- inventory_map.put("line_items",product_list);
- update_entry = zoho.inventory.updateRecord("Salesorders",organization_id,soid,inventory_map,"xxxxxxxxx");
This is the Inventory Function
- salesorderID = salesorder.get("salesorder_id");
- organization_id = "xxxxxxxx";
- crmid = salesorder.get("zcrm_potential_id");
- info crmid;
- dealid = Map();
- dealid.put("deal_id",crmid);
- deal = zoho.crm.getRecords("Deals",1,1,dealid,"xxxxxxxxx");
- product_details = salesorder.get("Order_Details");
- sales_map = Map();
- product_list = List();
- for each product in product_details
- {
- sales_map = Map();
- product_entry = product.get("group_name");
- product_item_name = product_entry.get("name");
- product_item_quantity = product.get("quantity");
- product_item_total = product.get("rate");
- //info product_item_description;
- sales_map.put("name",product_item_name);
- sales_map.put("Unit_Price_1",product_item_total);
- sales_map.put("Qty",product_item_quantity);
- product_list.add(sales_map);
- }
- info product_list;
- inventory_map = Map();
- inventory_map.put("Order_Details",product_list);
- update_entry = zoho.crm.updateRecord("Deals",organization_id,dealid,inventory_map,"xxxxxxxxxxx");