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.
[code]
var invoiceRecord = nlapiCreateRecord(‘invoice’);
var invoiceRecord = nlapiTransformRecord(‘customer’, netsuiteCustomerId, ‘invoice’, {
recordmode: ‘dynamic’
});
[/code]
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:
[code]
invoiceRecord.setFieldValue(‘entity’, netsuiteCustomerId);
[/code]
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