This article is relevant if you are performing NetSuite SuiteScript development and you need a lookup function for custom record scriptIDs.
Background
We have developed a NetSuite Advanced PDF Content Generator leveraging the FreeMarker template syntax. In this effort (subject to future article), we wanted to create a user interface that would allow the user to pick any record type to dynamically load into the template engine. Hence, in our NetSiuite Suitelet, we created a custom dropdown field that was of type “List/Record” against the list “Record Type”. This conveniently provides a list of all the custom record types. However, this dropdown returns the integer value of the custom record type, not the string internal ID which is used in most all of NetSuite’s SuiteScript record and searching APIs.
To solve this, do you hard code the string names to the integers as a static map? No! Thanks to fellow blogger and NetSuite SuiteScript enthusiast Joe Son, his article helped us see the solution. Here, we summarized his article into a custom function.
SuiteScript Function to Lookup Custom Record Internal IDs from Integer
function getCustomRecordType(internalId) { try { var filters = new Array(); filters.push(new nlobjSearchFilter("internalid",null,"anyof",internalId)); var columns = new Array(); columns.push(new nlobjSearchColumn("scriptid")); var results = nlapiSearchRecord("customrecordtype", null, filters, columns); if (results && results.length > 0) { return results[0].getValue("scriptid").toLowerCase(); } else { return null; }; } catch (e) { nlapiLogExecution("ERROR", "getCustomRecordType", e.message); }; };
Enhance your NetSuite Environment
The NetSuite platform is designed to be enhanced to fit business requirements and improve your operations. If you would like to get more out of your NetSuite system, let’s have a conversation.
Could you please give me a ample code to retrieve the internal id of a custom record using it’s script id using netsuite php toolkit?
Hello Rajitha,
You may need to create a custom NetSuite Resetlet to expose the function as contained in this article. Else, follow the logic for the criteria and column defintion to craft your own search.
Marty
Can we get the script id of built-in record types? Like for customer or employee? The List/Record for Record Types contain built-in record types as well.
Hello Atif,
Unfortunately, there does not appear to be a way that I know of to lookup native record types. One thought I have is to dynamically create a custom record, then a custom field, of type List, and then iterate the values of the dropdown. But in my work with my team, we created a central map in our Utilities Library and thus use these tools.
Marty
[Corrected version]
Here’s an SS2 version of Marty’s code:
function getCustomRecordType(internalId) {
const FUNCTION_NAME = SCRIPT_NAME + 'getCustomRecordType';
log.debug({
title: FUNCTION_NAME,
details: {
internalId: internalId
}
});
let searchObj = search.create({
type: 'customrecordtype',
filters: [
search.createFilter({
name: 'internalid',
operator: search.Operator.ANYOF,
values: [internalId]
})
],
columns: [
'scriptid'
]
});
log.debug({
title: FUNCTION_NAME,
details: {
searchObj: searchObj
}
});
const results = searchObj.run().getRange({
start: 0,
end: 1
});
log.debug({
title: FUNCTION_NAME,
details: {
'results.length': results.length
}
});
const scriptId = !!results ? results[0] : null;
log.debug({
title: FUNCTION_NAME,
details: {
scriptId: scriptId
}
});
return scriptId;
}
Hello Christopher. I (and the community) thank you!
Marty