Example of a RESTlet that Adds Multiple Records

The following example shows how to use a RESTlet to create several contact records in one call.

RESTlet

          /**
 * @NApiVersion 2.x
 * @NScriptType Restlet
 */
define([ 'N/record' ], function(record) {
    return {
        post: function(restletBody) {
            var restletData = restletBody.data;
            for (var contact in restletData) {
                var objRecord = record.create({
                    type : record.Type.CONTACT,
                    isDynamic : true
                });
                var contactData = restletData[contact];
                for (var key in contactData) {
                    if (contactData.hasOwnProperty(key)) {
                        objRecord.setValue({
                           fieldId : key,
                           value : contactData[key]
                        });
                    }
                }
                var recordId = objRecord.save({
                    enableSourcing : false,
                    ignoreMandatoryFields : false
                });
                log.debug(recordId);
            }
        }
    }
}); 

        

Example Post Call

To create records with this RESTlet, you would use the post method using a request body to send your values for the new contact records. For example:

          {"data":[{"firstname":"John","middlename":"Robert","lastname":"Smith","subsidiary":"1"},{"firstname":"Anne","middlename":"Doe","lastname":"Smith","subsidiary":"1"}]} 

        

Related Topics

SuiteScript 2.x RESTlet Script and Request Examples
Example Hello World RESTlet
Example of a RESTlet that Retrieves, Deletes, Creates, and Upserts a NetSuite Record
Example of a RESTlet that Manipulates Scheduled Script
Example of a Client Script that Calls a RESTlet
Example of a Suitelet that Calls a RESTlet
Example of a Shell Script that Calls a RESTlet

General Notices