Accessing Custom Field values within Deluge, using Map and List functionality

Accessing Custom Field values within Deluge, using Map and List functionality

Hello,

I am looking to create a custom function which will pull the placeholder and value data for each custom field for each line item on a Sales Order in order to make calculations with this newly created Map. I have not found a way to directly reference the item_custom_fields specifics without pulling them into a separate Map first. Ideally I would like to use the .get function to directly access the 'value' data found in a given custom field (based on a specific custom field 'placeholder' lookup) in order to use this information in calculations, but there does not seem to be a way to do this when multiple custom fields are defined and filled in for an inventory item.

So I am attempting to first pull all the custom field placeholder and value data out from each line item and then will work with this new Map for calculations.

// Get Sales Order Information from Map
salesorderID = salesorder.get("salesorder_id");
organizationID = organization.get("organization_id");
// Create mapping for specific custom field to be updated
allCustomFields = List();
CustomField = Map();
allLineItems = salesorder.getJSON("line_items");
for each  lineItem in allLineItems
{
    lineItemQty = lineItem.get("quantity");
    // get all custom fields for current line item, only those from inventory, not manually entered
    if(lineItem.get("item_id") != "")
    {
        currentItem = lineItem.getJSON("item_custom_fields");
        //search each custom field of current line item
        for each  currentCF in currentItem
        {
            // add label and value for matching custom field to be updated
            cfPlaceholder = currentCF.get("placeholder");
            cfValue = currentCF.get("value");
            CustomField.put(cfPlaceholder,cfValue);
        }
        info CustomField;
        allCustomFields.add(CustomField);
    }
}
info allCustomFields;

The "info CustomField;" on the Execute correctly shows all "placeholder":"value" key-value pairs pulled from the multiple custom fields associated with each inventory item. However, the "info allCustomFields;" only shows duplicate multiples of the last line item processed instead of each of the previous line items in the new List. It appears that the memory of the List is overwritten on each pass and I have tried .add in different areas of the script with the same effect. I have attempted to .clear the Map after adding it to the list but then this also ends up also clearing the List by the end.

Is there a way to run through these custom fields, add their placeholder and value data to a Map, add that Map to a new list, and run through all line items, with the output of the custom field data at the end? or a way to directly access this data instead of building a new Map?

Thank you,
Curtis