Hello,
Open your Zoho Inventory organization.
Navigate to Settings using the gear icon from the top-right corner.
Select Automation from the sidebar. Now click on the button adjacent to +New Workflow Rule.
Out of the four options from the drop-down, select Custom Functions.
Now let's add a name for this workflow rule and make sure that there are no spaces between words.
Select Sales Orders against module.
Add a description if you need one.
Now, the workflow type is going to be Event Based.
The condition to set shall be, "When a Sales Order is created".
And, for the trigger, it will be "When Sales Order status is Confirmed".
Now copy and paste this code snippet into the deluge pane:
salesorderID = salesorder.get("salesorder_id");
salesorderdate = salesorder.get("date").toDate();
organizationID = organization.get("organization_id");
authtoken = "Copy and paste your authtoken here";
mapper = Map();
customerID = salesorder.get("customer_id").toString();
//package_number = salesorder.get("salesorder_number").replaceFirst("SO","PA");
//mapper.put("package_number",package_number);
mapper.put("customer_id",customerID);
mapper.put("date",salesorderdate);
lineItems = salesorder.get("line_items").toList();
newLineItems = List();
for each lineItem in lineItems
{
lineItemMap = Map();
solineitemID = lineItem.get("line_item_id");
lineItemMap.put("so_line_item_id",solineitemID);
quantity = lineItem.get("quantity");
lineItemMap.put("quantity",quantity);
newLineItems.add(lineItemMap);
}
mapper.put("line_items",newLineItems);
jsonString = Map();
jsonString.put("JSONString",mapper);
response = invokeurl
[
url :"https://inventory.zoho.com/api/v1/packages?authtoken=" + authtoken + "&salesorder_id=" + salesorderID + "&organization_id=" + organizationID
type : POST
parameters:jsonString
];
info mapper;
info response.toMap();
//shipment
pack=response.get("package");
packid=pack.get("package_id");
ship=Map();
ship.put("date",salesorderdate);
ship.put("delivery_method","dhl"); //REPLACE WITH SHIPPING CARRIER NAME OR DELIVERY BY SELF
jsons=Map();
jsons.put("JSONString",ship);
resp = invokeurl
[
url: "https://inventory.zoho.com/api/v1/shipmentorders?package_ids="+packid+"&salesorder_id=" +salesorderID+ "&authtoken="+authtoken+"&organization_id=" + organizationID
type: POST
parameters: jsons
];
info resp.toMap().get("message");
Copy and replace your authtoken number with the text on line 4 of the code.
authtoken = "copy and paste your authtoken here"; to something like, authtoken = "67xxxxxxxxxxxxxxxxx".
You can change the carrier name/shipping medium by making changes to line 38 of the code that says: ship.put("delivery_method","dhl"); //REPLACE WITH SHIPPING CARRIER NAME - for e.g., "dhl" can be replaced with "fedex" or something of your choice like say, "delivery_by_self" or "picked_up_by_customer".
Note: If you have enabled auto-generation of package numbers for your organization, then you don't need these two lines:
//package_number = salesorder.get("salesorder_number").replaceFirst("SO","PA");
//mapper.put("package_number",package_number);
Once everything is ready, hit Save.