Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

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.

 

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

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

  1. 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?

    Reply
  2. 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.

    Reply
  3. [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;
    }

    Reply

Leave a Reply

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