Zoho Invoice custom function for Estimate module
Hi!
I using invoice.zoho.
I want to update
"quantity" after push custom fields (Ex: NightQty and Qly):
quantity = NightQty * Qly
I created a custom function for Estimate module in Custom functions tab:
estimateID = estimate.get("estimate_id");
organizationID = organization.get("organization_id");
estimateMap = zoho.books.getRecordsByID("Estimates",organizationID,estimateID).get("estimate").toMap();
itemJSON = estimateMap.get("line_items").toList();
updatedLineItems = List();
for each item in itemJSON
{
item_CFs = item.get("item_custom_fields").toList();
updatedLineItem = Map();
updatedLineItem.put("line_item_id",item.get("line_item_id"));
nights = 0;
roomqty = 0;
for each item_cf in item_CFs
{
if(item_cf.get("label").equalsIgnoreCase("NightQly"))
{
nights = item_cf.get("value").toDecimal();
}
else if(item_cf.get("label").equalsIgnoreCase("Qly"))
{
roomqty = item_cf.get("value").toDecimal();
}
}
qty = nights * roomqty;
updatedLineItem.put("quantity",qty);
updatedLineItems.add(updatedLineItem);
}
json = Map();
json.put("line_items",updatedLineItems);
response = zoho.books.updateRecord("Estimates",organizationID,estimateID,json);
info response.get("message");
And I added to "Workflow Rules". But this function not working and I receive error:
Custom Function Estimate failed to execute for the workflow Update Estimate.
by Zoho Invoice.
This code worked on Invoice module with "zoho intergration" like "zoho.invoice.getRecordByID()" and "zoho.invoice.update()".
Can help me?