Tip #3 Automating total item weight calculation for your sales orders in Zoho Inventory

Tip #3 Automating total item weight calculation for your sales orders in Zoho Inventory


Hope the day is treating you well.
Last week, we saw how we could automate the calculation of total shipping charges from numerous shipments for your sales orders and invoices. This week, we will see how you can automate the calculation of total item weight for your sales orders. 

How does this work?
First, you are required to capture the weight of all your items using a custom field. And when you create a sales order, you can either have the system display the individual weights for you or you can manually enter new weights. You are also required to define a custom field under sales orders and packages called Weight to capture the total package weight. Through the custom function, the system will then add up the individual weights of items to arrive at a total weight and display it on your sales orders and packages. Later when you ship via a carrier, you can refer manually to this weight and input them into the shipment order to generate shipping rates.

Note: This custom function works only if a sales order has a single package. If there are multiple packages, then please note that this function will display the total weight of all items in the sales order inside of every package and not the total weight of items present inside that package. 

What do you need before writing the custom function?

How do I set it up?

Log in to your Zoho account and click on this link to generate an Auth Token which is required to make this work.

  • 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.

  • Choose "Sales Orders" against the module field.

  • Add a description if you need one.

  • Now, the workflow type is going to be "Event Based".

  • And for the trigger, we are going to choose the option - "when a Sales Order is created".

In the deluge pane, we are going to copy and paste the following code snippet:

authtoken = "Copy and paste your authtoken here";
salesorderID = salesorder.get("salesorder_id");
salesorderdate = salesorder.get("date").toDate();
organizationID = organization.get("organization_id");
for each line in lineitems
for each cf in cfs
if(cf.get("label").toString().equalsIgnoreCase("weight")) /*replace with item level custom field name*/
weight.add(cf.get("value").toDecimal() * line.get("quantity"));
for each index j in weight
wei=wei + weight.get(j).toDecimal();
info wei;
cf1.put("label","Weight"); /* replace with sales order custom field */
res=zoho.inventory.updateRecord("SalesOrders", organizationID,salesorderID, bson);
info res.toMap().get("message");

  • Before you save, you are required to copy and paste your auth token inside the quotes in the 1st line that says:

    • authtoken = "Copy and Paste your auth token in place of this text";

    • The auth token is a critical piece of information that helps the system identify you, so keep yours safe and confidential. Do not share it with anyone, not even folks from Zoho.

  • Now, hit Save to finish.

Henceforth, the total weight of all your items in a sales order you make will be calculated automatically and updated to the package that is associated with it. 

Don't use this, if you have multiple packages for a single order.

Hope this makes shipping a little more easier for you. Have you tried custom functions for your business? Email us your recipes (scenarios and code snippets), questions and suggestions to support@zoho-inventory.com.

Until next time!

Your everyday end user,

Ajay Aadhithya Chandrasekaran

Zoho Inventory