Hello,
We are trying to create a
custom function which will sum the total quantity of all line items on a
Sales Order and output this to a custom field on the Sales Order. We
have a custom field called "Sum of Line Items" which is a Number type
and is a Default Value of 0 (API Field Name is cf_sum_of_line_items).
The custom function is written inside of Deluge with Sales Order as the
Module chosen:
salesorderID = salesorder.get("salesorder_id");
organizationID = organization.get("organization_id");
sumOfLineItem = 0;
// Loop through line items and add sum to total
allLineItems = salesorder.getJSON("line_items");
for each lineItem in allLineItems
{
lineItemQty = lineItem.get("quantity");
sumOfLineItem = sumOfLineItem + lineItemQty;
}
info sumOfLineItem;
// Create List for Custom Fields update
CustomFields = List();
CustomField = Map();
CustomField.put("label","Sum of Line Items");
CustomField.put("value",sumOfLineItem);
CustomFields.add(CustomField);
soUpdate = Map();
soUpdate.put("custom_fields",CustomFields);
response = zoho.inventory.updateRecord("SalesOrders",organizationID,salesorderID,soUpdate);
info response;
When we execute this code as an Admin user through the Custom Function script edit screen we receive the following response output:
{"code":57,"message":"You are not authorized to perform this operation"}
The
sumOfLineItem reports correctly but it will not update the record's
custom field "Sum of Line Items" from 0 to 16 (as an example).
My
understanding is that working within Automation > Custom Functions
and coding in Deluge does not require an explicit API connection to work
on this update. Is that correct? And is the custom_fields area the
correct list to update or is custom_field_hash the one I should be
attempting to update? (attempts to update both result in the code 57).
What syntax or update method is incorrect in this code?
Thank you,
Curtis