NetSuite Tip: Retrieve Custom Record Type Internal Integer IDs

This article is relevant if you are developing a NetSuite SuiteScript program and you need to get the recordtype integer value internal ID.

Background

Most of the time, when developing NetSuite SuiteScript programs to work with records, you can reference the string description of a recordtype for making calls into nlapiLoadRecord functions.  For example, when you work with a Sales Order, the string representation of the internal recordtype ID is “salesorder” .   However, when you work with NetSuite Custom Record types, both string and integer values represent the recordtype.

When you are developing a NetSuite application, sometimes you need to provide the integer value of the recordtype ID versus the string representation.  For example, I was creating a NetSuite SuiteFlow workflow program to automatically add a user note upon the submit of the main record.  To attach the automatically created user note to the custom record type, I needed  the recordtype ID in integer form.  To get the recordtype ID integer value, I can simply look at the URL and gather the rectype ID.  See below:

https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=93&id=3&whence=

While I may have been able to create a constant in my code to represent 93, my plans was to move this workflow through a SuiteBundle to other NetSuite accounts.  Consequently, I needed a way to lookup the recordtype internal ID integer from the static string representation.  As such, I developed the following SuiteScript function so the program is portable.

Custom SuiteScript Function to Lookup Recordtype Integer Internal IDs

The following function can be used to lookup custom record types.  It is not meant to be used with native NetSuite recordtypes.

//helper function to get the custom record rectype number
function getCustomRecordTypeValue(name) {
	//leverage NetSuite's URL generator to get the record type
	return getURLParameterByName('rectype', nlapiResolveURL('RECORD', name))

	//url parser helper function
	function getURLParameterByName(name, url) {
		name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
	        results = regex.exec(url);
	    return results === null ? "" : results[1].replace(/\+/g, " ");
	};
};

NetSuite List of RecordType Integer based Internal IDs

As of the time of this article the only reference I could find of native NetSuite integer recordtype internal IDsrevealed the following (search Help on Using “Internal IDs, External IDs, and References”):

Record Type typeId
Account -112
Accounting Period -105
Bin -242
Call -22
Campaign -24
Case -23
Class -101
Competitor -108
Contact -6
Customer -2
Customer Category -109
Department -102
Email Template -120
Employee -4
Employee Type -111
Entity Status -104
Event -20
Issue -26
Item -10
Item Type -106
Job (Project) -7
Location -103
Module -116
Opportunity -31
Partner -5
Product -115
Product Build -114
Product Version -113
Project (Job) -7
Role -118
Saved Search -119
Subsidiary -117
Task -21
Transaction -30
Transaction Type -100
Vendor -3
Vendor Category -110

I found a NetSuite help page that outlines the supported native NetSuite recordtypes and their string representation of internal IDs (Search the Help for “SuiteScript Supported Records”). So far, I haven’t found a way to programmatically lookup the integer based internal IDs for all these recordtypes.  But I can tell they are all negative value integers which leads to me to believe I could develop an algorithm to loop through a function to discover them (a topic for a future article).

Innovate with NetSuite’s Platform

NetSuite’s SuiteScript platform is great for extending functionality and fitting business requirements well.  The nature of the development environment sometimes requires getting at information and constructs that are not easily answered.  If you are looking for help to extend your NetSuite business application, contact us.

 

 

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

| Tags: , , , | Category: NetSuite, Technical | 6 Comments

6 thoughts on “NetSuite Tip: Retrieve Custom Record Type Internal Integer IDs

  1. Nice idea!

    And not that it makes a huge difference since you won’t be using it in a loop but the function getURLParameterByName is really overkill for this job (and isn’t really a good example of a general function for its purpose. It doesn’t handle array parameters, doesn’t unescape other than ‘+’ to a space). A more efficient alternative would be:


    function getCustomRecordTypeId(recName){
    var idMatch = (/\brectype=(\d+)/).exec(nlapiResolveURL('RECORD', recName));
    return idMatch ? idMatch[1] : null;
    }

  2. Marty Zigman says:

    Thanks Brett. Your’s is easier to understand as you target the rectype keyword and ask for a digit in your regex. Clean. I’ll go with it.

    Marty

  3. Dan Stegmaier says:

    I’ve been able to do similar within a Suitelet by using the following code within a request.

    var recIdUrl = request.getAllParameters();
    recId = recIdUrl[“rec_id”];

    In my case, I had a client script open the link in a new tab and pushed the record ID to that url as seen in my example below. (Was a link to trigger the Suitelet. Those two lines of code are able to read the RecId value in the URL. This should work with anything that reads: variable=

    https://system.netsuite.com/app/site/hosting/scriptlet.nl?script=300&deploy=1&rec_id=172

    I believe it can only be used in User Event and Suitelts. Figured I’d share that tiny bit of code that I’ve found useful as it seems very similar to what you’re trying to do here.

  4. Marty Zigman says:

    Hey Dan,

    Really good! Thank you for adding the thinking.

    Marty

  5. Eric says:

    Great article! I’m trying to figure out why the description and sub-total item types don’t get returned on my invoice. They have a negative Id so I hope your article helps me figure out how to do something similar in item types. Thank you!

  6. Stefan Reeder says:

    Hey Marty

    Stumbled across this old post while I was trying to the same thing, mainly for hiding specific DOM elements on page load for custom child records.

    Found the easiest way to get the ID number for custom records was really simple. This is important since the ID number may change when deploying a bundle or SDF package to a new account.


    var myrecord = record.create({type: "customrecordchild_record"});
    recnum = shipItem.getValue({fieldId: "rectype"});

    Seems to have minimal impact on performance as well.

Leave a Reply

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