NetSuite Lookup: Get Custom Record Script ID from Internal ID Integer

NetSuite Technical

Tags: , , ,

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.

 

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

6 thoughts on “NetSuite Lookup: Get Custom Record Script ID from Internal ID Integer

  1. Rajitha says:

    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?

  2. Marty Zigman says:

    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

  3. Atif says:

    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.

  4. Marty Zigman says:

    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

  5. Christopher Alexande says:

    [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;
    }

  6. Marty Zigman says:

    Hello Christopher. I (and the community) thank you!

    Marty

Leave a Reply

Your email address will not be published. Required fields are marked *