Open your Zoho Inventory organization.
Click on the gear icon from the top-right corner to select Automation from the drop-down.
Inside of Automation, select the drop-down near the +New Workflow button and select Custom Functions.
Give your workflow a name without any spaces between words.
The module will be Invoices.
The condition for this custom function shall be "When an Invoice is created".
The trigger point for this function will be "Immediate".
Copy and paste the code segment below inside the Deluge pane:
shipamt = List();
authtoken = "Copy and paste your authtoken here";
invoiceID = invoice.get("invoice_id");
invoicedate = invoice.get("date").toDate();
organizationID = organization.get("organization_id");
res = invokeurl
[
url :"https://inventory.zoho.com/api/v1/invoices/" + invoiceID + "?organization_id=" + organizationID + "&authtoken=" + authtoken
type :GET
];
inv = res.get("invoice");
soid = inv.get("salesorder_id");
//replace authtoken and orgid
response = invokeurl
[
url :"https://inventory.zoho.com/api/v1/salesorders/" + soid + "?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("invoice_number",invoice.get("invoice_number"));
bson.put("customer_id",invoice.get("customer_id"));
bson.put("shipping_charge",sumamt);
fin = zoho.inventory.updateRecord("Invoices",organizationID,invoiceID,bson);
info fin.toMap().get("message");
Make sure you copy and paste the auth token number that you had generated earlier to line 2 of this code fragment that says: authtoken = "Copy and paste your auth token here";
Hit Save to finish.
Now every time you make an invoice for a shipped sales order, the total shipment charge will be updated automatically.
Writer is a powerful online word processor, designed for collaborative work.