Hello again,
How does it work?
Let's suppose you order items A (20 pcs) and B (35 pcs) from a vendor. Now the vendor delivers only 15 pcs of A and 7 pcs of B to your warehouse. When you record a purchase receive for these items, the custom function will automatically send out an email notification to the vendor telling them that they are yet to deliver 5 pcs of A and 28 pcs of B. Similarly, the vendor will be informed of all "yet to arrive items" until all of them have been received by you.
Setting up the custom function:
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 to this workflow rule and make sure that there are no spaces between words.
Select Purchase 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 Purchase Order is" "Created or Edited".
Function shall be executed "When any field is updated".
And set the frequency of execution to "Everytime".
Click on the Apply Advanced Filter option.
The trigger to execute this function shall be: "When" the "Purchase Receive Status" "is" "Partially Received".
Now copy and paste this code snippet into the deluge pane:
purchaseorderID = purchaseorder.get("purchaseorder_id");
purchaseorderdate = purchaseorder.get("date").toDate();
organizationID = organization.get("organization_id");
ponum = purchaseorder.get("purchaseorder_number");
authtoken = "XXXXXXXXXXXXXXXXXXXXXXX";
vendorID = purchaseorder.get("vendor_id");
str = "<u>YET TO RECEIVE FOLLOWING ITEMS</u>";
res = invokeurl
[
type :GET
];
po = res.get("purchaseorder");
//info po;
prdet = po.get("line_items").toList();
//info prdet;
i = 1;
lineitems = purchaseorder.get("line_items");
for each det in prdet
{
if(det.get("quantity_ordered").toDecimal() != det.get("quantity_received").toDecimal())
{
iid = det.get("item_id");
for each line in lineitems
{
if(iid == line.get("item_id"))
{
sku = line.get("sku");
prate = line.get("rate");
break;
}
}
info sku;
info prate;
str = str + "<br>";
str = str + "<br>";
str = str + i + ".";
str = str + " " + det.get("name");
str = str + " " + " " + "[ SKU : " + sku + " ] ";
str = str + "-";
str = str + " " + " ";
tbr = det.get("quantity_ordered").toDecimal() - det.get("quantity_received").toDecimal();
str = str + " Quantity : " + tbr.toString();
i = i + 1;
}
}
//info str;
if(str.contains("Quantity"))
{
// info vendorID;
resp = invokeurl
[
type :GET
];
cont = resp.get("contact");
contactdet = cont.get("contact_persons").toList();
//info contactdet;
for each deta in contactdet
{
if(deta.get("is_primary_contact").toString().equalsIgnoreCase("true"))
{
vendoremail = deta.get("email").toString();
break;
}
}
info vendoremail;
sendmail
[
from :zoho.adminuserid
to : vendoremail //EMAIL ID
subject :"REGARDING PURCHASE ITEMS FOR " + ponum
message :str
]
}
else
{
info "all received";
}
Hope this helps in reducing your product wait time and improves your relationship with your vendors.
Until next time.
Your everyday end user,
Ajay Aadhithya Chandrasekaran
Zoho Inventory