SuiteScript – Dealing with Item Types

I wanted to activate an inactive item from code. Interestingly enough, I could search for the item using the base type of ‘item’. However, I could not update the item unless I used the item’s true type. Here’s my reminder to myself of where the true type comes from.

If you search for an item using the base type of ‘item’, the only column that can be returned in the search results is ‘type’ which equals ‘item’. You’ve learned nothing!

Field Explorer

Here is the doc on Item search fields. It comes from…

Record Browser

And if you scroll way down the page into the “Search Columns” section…

Search Results

results[0].getFieldValue(‘type’) == ‘item’     // Not helpful!

You can’t use nlapiLoadRecord(‘item’,…) or nlapiSubmitField(‘item’,…)

So here’s the secret handshake. Search using the type of ‘item’ and then check the recordType property on the returned records.

Debugger

This seems way more difficult than it needs to be. Oh well, just another day of writing software!

Here’s my finished product.

Restlet

And code you can cut and paste…

ActivateItem: function(internalid) {
try {
var filter =new nlobjSearchFilter(‘internalid’, null, ‘is’, internalid);
var columns =new Array();
columns.push(new nlobjSearchColumn(‘itemid’));
var results = nlapiSearchRecord(‘item’, null, filter, columns)
var recordType =null;
if (results.length >0) {
recordType = results[0].recordType;
}
if (recordType !=null) {
nlapiSubmitField(recordType, internalid, ‘isinactive’, ‘F’);
}
return”success”;
} catch (err) { return “error: ” + err.message; }
}

One thought on “SuiteScript – Dealing with Item Types

  1. Michoel Chaikin says:

    You could just do nlapiSubmitField(nlapiLookupField(‘item’, internalid, ‘recordType’), internalid, ‘isinactive’, ‘F’)

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s