In my afterSubmit script, I'm trying to get the It...
# suitescript
e
In my afterSubmit script, I'm trying to get the Item Name, but it's returning undefined. Am I missing something?
Copy code
let salesOrder = context.newRecord;

let itemName = salesOrder.getSublistValue({
    sublistId: 'item',
    fieldId: 'item_display',
    line: 0
}); // Returns Undefined
m
You should be able to use
getSublistText()
on the
item
field to get the item name.
Copy code
let itemName = salesOrder.getSublistText({
    sublistId: 'item',
    fieldId: 'item',
    line: 0
});
t
double check if the fieldId is correct
e
@Mike Robbins when I tried .getSublistText I got an error
"Invalid API usage. You must use getSublistValue to return the value set with setSublistValue"
Which didn't feel right, as I'm not setting any values in the sublist via script. But that's the error I. was getting
d
You probably need to get the order ID from context.newRecord, then do an explicit record.load.
m
@ericbirdsall Yeah, that’s going to happen. If you’re using
.setSublistValue
on that field before calling
getSublistText
, you’ll get that message. Might be time for a call to
search.lookupFields
or
search.create
if you need to get the item name for all lines.
getSublistText
works by itself in afterSubmit for me, and I can duplicate your error message by setting a new value in that field with
.setSublistValue
right before calling
getSublistText
.
e
@Mike Robbins Thanks for checking on that for me. I see that I do have a .setSublistValue in another function of my afterSubmit. So I'll find a way around this now