Custom field update from Deluge custom function giving permission error

Custom field update from Deluge custom function giving permission error

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

    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