You have a Sales or Purchase Order with hundreds of items, and you are tasked to determine the item type so that you can later add it to a new custom column in the transaction record. What would you do?
You can use the sample code below as a guide. In this example, I wrote the script to run via console when you have opened any record type that has an item sublist, that includes Sales Order, Purchase Order, Invoices, and many more.
And since this is designed to run via console, just press F12 then copy and paste this code then press Enter.
require(['N/currentRecord','N/search'], function(currentRecord, search){
var rec = currentRecord.get();
var sub = rec.getLineCount({sublistId:'item'});
console.log("Item Sublist Length: "+ sub);
for(var i = 0; i < sub;i++){
var itemId = rec.getSublistValue({
sublistId : 'item',
fieldId : 'item',
line : i
});
var itemType = search.lookupFields({
type: search.Type.ITEM,
id: itemId,
columns:'type'
});
console.log('Item ID: '+ itemId +', Item Type: '+ itemType.type[i].value);
console.log(itemType);
};
})
Related SuiteAnswers:
43711 search.lookupFields(options)
------
Found this tip helpful? Others might too! Let us know by leaving a reaction or a comment below.