NetSuite Customization: Extracting Item Types from nlobjSearchRecord

Problem

When working with the various item types (Inventory items, Non-Inventory items, Assembly items, Service items, etc.) supported by NetSuite. I’m sure you must have encountered scenarios where you have a list of internal item ids and you want to extract or fetch some of those items for use in some operation. For example, performing an update on the item record.

Now, when we use the nlapiSearchRecord command to extract items from a list of items, you always record the object type as ‘item’ (as shown below).

nlapiSearchRecord (‘item’,’internalid’,filters,columns);

But when you need to extract (fetch) or create items using the nlapiLoadRecord / nlapiCreateRecord commands, you need to specify the record type of the item you want, rather than just using the general term ‘item’, as shown below. Here:

nlapiLoadRecord(‘item’,’11111′) will not work 

but nlapiLoadRecord(‘inventoryitem’,’11111′) will work 

Solution

When you execute the nlapiSearchRecord command, it returns an array of nlobjSearchResult.

The nlobjSearchResult array has the ‘recordType’ property on the server and the ‘type’ property at the client end, and thus provides a record type that you can use in the nlapiLoadRecord function. For example:

var cols = [];
var recs;
var filters = [];
var itemInternalIds = ['111', '112', '113'];
var currentItemLoaded;
filters.push(new nlobjSearchFilter('internalid', null, 'anyof', itemInternalIds));
// Get List of Records
recs = nlapiSearchRecord('item', null, filters, cols);
if(!!recs & recs.length > 0) {
for(var i = 0; i <recs.length; i++) {
currentItemLoaded = nlapiLoadRecord(recs[i].recordType, recs[i]); // Use recs[i].type for client script
// Further operations ......

// Further operations ......

// Further operations ......
}
}

As you can see, by using the solution above you can save the extra units involved in executing the nlapiLookupField/nlapiSearchRecord function, in order to fetch a specific item type. Of course if you use this call to load and process a large number of item records, then obviously it will be more resource intensive.

If you have a NetSuite customization requirement you would like to discuss, or would like to know more about our NetSuite customization services, please get in touch with us  

It's only fair to share...Tweet about this on TwitterShare on LinkedInShare on Google+Share on Facebook

Shoaib Mehmood

Leave a Reply

Your email address will not be published.