Hello,
Hope you are doing good today.
Method 1. Auto-updating total shipment charge to a sales order:
Open your Zoho Inventory.
Click on the Gear icon from the top-right corner, and select Automation from the drop-down.
Inside the Automation page, click on the drop-down button adjacent to +New Workflow button to select Custom Functions from the drop-down.
Give your workflow a name without any spaces between words.
Set Module as Sales Orders.
Set the condition as: "When a Sales Order is created or edited".
Execute the Workflow "when any field is updated". and choose "Everytime".
Click on the advanced filter and set the condition as: "When Shipment Status is Shipped".
Finally, you are required to set the trigger point for this function as "Immediate".
Copy and paste the code segment below into the Deluge pane:
authtoken = "Copy and paste your auth token here";
shipamt = List();
salesorderID = salesorder.get("salesorder_id");
refnum = salesorder.get("reference_number");
info refnum;
salesorderdate = salesorder.get("date").toDate();
organizationID = organization.get("organization_id");
//replace authtoken and orgid
response = invokeurl
[
url :"https://inventory.zoho.com/api/v1/salesorders/" + salesorderID + "?authtoken=" + authtoken + "&organization_id=" + organizationID
type :GET
];
so = response.get("salesorder");
pkg = so.get("packages").toList();
sid = List();
for each pk in pkg
{
sid.add(pk.get("shipment_id"));
}
i = 0;
sumamt = 0;
for each index i in sid
{
resp = invokeurl
[
url :"https://inventory.zoho.com/api/v1/shipmentorders/" + sid.get(i) + "?authtoken=" + authtoken + "&organization_id=" + organizationID
type :GET
];
shipdet = resp.get("shipmentorder");
charges = shipdet.get("shipping_charge").toDecimal();
sumamt = sumamt + charges;
}
info sumamt;
bson = Map();
bson.put("salesorder_number",salesorder.get("salesorder_number"));
bson.put("customer_id",salesorder.get("customer_id"));
bson.put("shipping_charge",sumamt);
fin = zoho.inventory.updateRecord("SalesOrders",organizationID,salesorderID,bson);
info fin.toMap().get("message");
Make sure you copy and paste the auth token number that you had generated earlier to line 1 of this code fragment that says: authtoken = "Copy and paste your auth token here";
Hit Save to finish.