Hey folks! I am trying to get some data on all the...
# suitescript
m
Hey folks! I am trying to get some data on all the items on a Sales Order, and I've started with something like this:
var newRecord = context.newRecord;
var itemName = newRecord.getSublistValue(
{
sublistId:'item',
fieldId: 'item',
line: i // this is in a loop
});
What I don't understand is why fieldId isn't the field Id I was expecting. For example, 'item' in fieldid in the above code returns the Internal Id of an item, but on the item's record, Internal Id is 'internalid' (not 'item'). Why are these different? How do I grab different/custom fields on an item that is on a Sale Order, if those item's field's id isn't recognized in this call? I am guessing this is just the wrong call to use, but it does return the right internalIds as 'items.' Thanks for any help!
specifically the item sublist
https://chrome.google.com/webstore/detail/netsuite-field-explorer/cekalaapeajnlhphgdpmngmollojdfnd may interest you if you are having issues with field internal ids
basic answer to your question is that fields on the item sublist are not fields on the item record
m
Ok, thanks.. I will take a look at top link and add that extension!
That chrome extension is really cool, thanks! I'll have to dig into that first link you sent because if I used the ids in the bodyFields from the chrome extension, those don't work in that getSublistValue call.
b
look at the lineFields key for the item sublist
as you can probably guess, fields on transaction body are not fields on the item sublist
m
Ah, ok, thanks . . . I see that now. I had no idea that it was handled that way. Is there a way to add custom fields to the Item Sublist?
m
thanks a ton for that link!
sometimes navigating Netsuite's docs/knowing where to look is more tricky than writing the actual code!
b
you will want to use sourcing if you want the field to automatically populate with the value from the item https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_N2839623.html
m
ok, thank you. I'll definitely have to dig into this info and mess around. I know that in trying to figure out my initial question used a few of the internal ids from the item sublist and still got unusual data to return (like just a 1 for price), so I'll start by trying to figure that part out and then move onto setting up and using custom fields.
b
getSublistValue returns internal ids for select fields getSublistText returns the text for the select fields
👍 1
😎 1
m
So this is a user event script. As such, it appears I will not be able to use the getSublistText ?
b
it depends. if the field was set using setSublistText, then yes
m
It wasn't. All I am trying to do is loop through items on a set of Sales Orders, and check some fields and then do some asks depending on the value/text in those fields
b
in general, get used to working with internal ids
m
Yes, that list you sent was helpful and I can see the difference in the ids now. But I still haven't figured out how to grab the data I need from the items on a Sales Order. I guess part of it is inexperience, but even looking at that Records Browser, I am not seeing a correlation for most fields. For example, we have a field for an item's SKU, with an id of 'itemid,' but I haven't figured out what that is in the Records Browser, and it isn't a custom field. Beyond that, I'm also not sure I am going to be able to get what I need since the getText won't work. Definitely a learning curve here, and typically this would be such a simple task/script to write.
b
its not always the same, but you can try using item_display
otherwise use N/search to lookup the field
or create a custom transaction column that uses sourcing to get your field there
m
ok, thanks, I will look into it.
b
keep in mind, transactions only show some fields from items, not all
m
I haven't really got to it yet because I can't even get the simple fields back, but can fields be added: https://1259134.app.netsuite.com/app/help/helpcenter.nl?topic=LIST_CUSTCOLUMNFIELD&whence=
b
yes, thats how you add custom transaction line fields
m
@battk So if I have created a custom transaction line field, and need it sourced from a multi-select custom item field . . . . NS won't allow that, yes? I saw that in the docs. Do you know of a good work-around? Thanks again for your help on this. I got through the sublist ids and item ids, then I got some custom transaction line fields sourced, and was making progress, and then I run into sourcing from a multi-select!
b
you will probably have to break out N/search to get the value of your field
there are no multiselects at the line level
m
Ok, thank you (yet again!) . . . I'll have think about what kind of search to build -- but basically build/run a search on this event that gets the items on the order, and then use that and grab the actual item fields instead of the transaction line fields . . . I think, ha!
and I was making progress with the info you gave me Friday . . . until I hit the multi-select!