Tip #4.2 Auto-creating package and shipment records for your online sales orders

Tip #4.2 Auto-creating package and shipment records for your online sales orders

Hello again,

 

I hope you've checked out the part 1 of this post where we auto-create packages and shipments for your offline orders. This is part 2, and here we will see how we can automatically create packages and manual shipment orders for your online sales orders (or in other words, orders generated from Amazon, Etsy, Ebay or Shopify).


Setting up the custom function:

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. Click on the button adjacent to +New Workflow Rule.

  • Select Custom Functions from the drop-down.

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

  • Now copy and paste this code fragment into the deluge pane:

salesorderID = salesorder.get("salesorder_id");

salesorderdate = salesorder.get("date").toDate();
organizationID = organization.get("organization_id");
authtoken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
//replace the value with your authtoken value
sal = invokeurl
[
url :"https://inventory.zoho.com/api/v1/salesorders/" + salesorderID + "?authtoken=" + authtoken + "&organization_id=" + organizationID
type :GET
];
temp = sal.get("salesorder");
// info temp;
new = temp.get("sales_channel");
info new;
if(!new.equalsIgnoreCase("direct_sales"))
{
mapper = Map();
customerID = salesorder.get("customer_id").toString();
//uncomment the below two lines if you had not enabled auto package number generation
//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
{
if(lineItem.get("name").isNull())
{
continue;
}
lineItemMap = Map();
solineitemID = lineItem.get("line_item_id");
lineItemMap.put("so_line_item_id",solineitemID);
quantity = lineItem.get("quanity");
lineItemMap.put("quantity",quantity);
newLineItems.add(lineItemMap);
}
mapper.put("line_items",newLineItems);
jsonString = Map();
jsonString.put("JSONString",mapper);
info jsonString;
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().get("message");
pack=response.get("package");
packid=pack.get("package_id");
ship=Map();
ship.put("date",salesorderdate);
ship.put("delivery_method","dhl"); //REPLACE WITH YOUR SHIPPING CARRIER NAME
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");
}
else
{
info "SO from direct sales";
}
  • Copy and replace your authtoken number inside the code.

  • You can change the carrier name/shipping medium by making changes to this line: ship.put("delivery_method","dhl"); //REPLACE WITH SHIPPING CARRIER NAME.

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

Henceforth, whenever an online sales order gets generated within Zoho Inventory, a package and a manual shipment record will be created for it.

Until next time.

Your everyday end user,
Ajay Aadhithya Chandrasekaran
Zoho Inventory

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now