nlapiCreateRecord vs nlapiTransformRecord - What's the difference? nlapiCreateRecord vs nlapiTransformRecord - What's the difference?

NetSuite Restlet development can be hard; finding documentation is almost next to impossible. I've finally had a personal break through of:

What is the difference between nlapiCreateRecord and nlapiTransformRecord?

This article assumes that you have some NetSuite experience and have created a NetSuite Restlet. I have written a previous article that describes how to authenticate with NetSuite for calling a Restlet using token based authentication that should help you get up-to-speed.


Let's begin by a quick code example of what each method looks like in our JavaScript code: If you're just getting started be sure to read Netsuite API Developer's Guide first.


var invoiceRecord = nlapiCreateRecord('invoice');
var invoiceRecord = nlapiTransformRecord('customer', netsuiteCustomerId, 'invoice', {
recordmode: 'dynamic'
});

In the first example - using the create record syntax - we are creating an empty invoice record that has no information on it and we will need to populate all of the information.

However, In the second example where we use the transform record, we are actually taking a NetSuite customer object and transforming it into an invoice object.

The difference is: when I transform the object it automatically associates data from the NetSuite customer to the NetSuite invoice record allowing me to not have to setup as much data about the NetSuite customer for this new invoice.

If you are using the nlapiCreateRecord you would need to perform a second step to associate the invoiceRecord with the actual customer:


invoiceRecord.setFieldValue('entity', netsuiteCustomerId);

In both of these examples there is an assumption that you already know the NetSuite Customer's internal ID. In these examples I am using the variable name netsuiteCustomerId that you will need to have populated or the code adapted to match your variable name.

For a full list of nlapiTransformRecord options I was  able to find this useful link to show the various types that a record can be transformed to:

https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4267258715.html

Published on May 27, 2022

Tags: nlapiTransformRecord | nlapiCreateRecord | NetSuite

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.

Tutorials

Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.