Client Script: context.fieldId is 'item' when sele...
# suitescript
c
Client Script: context.fieldId is 'item' when selecting any field on the line item (sales order); is this as expected? I only want to fire the logic when the item sublist field is selected, not any field on the item sublist.
a
It depends, which entry point? how your code looks like?
c
function postSourcing(context) { const sublist = context.sublistId || ''; const sublistField = context.fieldId || ''; log.debug( 'User Selected',
Sublist: ${sublist}, Sublist Field:${sublistField}
) if (sublistField !== 'item') { return } }
a
Client Scripts are tricky (no very good designed in my opinion), postSourcing is especially tricky because selecting an Item would trigger multiple postSourcing events since a bunch of other fields source data after that. I will look at a postSourcing sample to share here with you when I have a minute.
c
All I really wanted to do was run a function when the item field is selected.
e
That might be a lineInit or fieldChange event, inside that you need to check the list and then the field.
c
For completeness, here's the context.
Despite clicking into the qty or value field, the fieldId is always item.
a
The way you debug this is by logging the postSource events that happen when you select an Item and determine which one is the last one, then go from there.
Copy code
if (scriptContext.sublistId !== 'item') {
            
            return;
        }
        console.log(`postSourcing Sublist: ${scriptContext.sublistId}`);
        console.log(`postSourcing Field: ${scriptContext.fieldId}`);
💯 1