NetSuite Integration: Hand Coded vs. Automated Approach

DZone 's Guide to

NetSuite Integration: Hand Coded vs. Automated Approach

Hand coding a NetSuite integration for your business means heavy coding and higher cost. Learn how to take advantage of a more automated approach.

· Integration Zone ·
Free Resource

NetSuite offers stellar Software as a Service (SaaS) products for accounting, operations, cloud relationship management (CRM), and eCommerce. It enables interdepartmental coordination by uniting accounting, sales, and support with on a single interface. However, teams face difficulties when the cloud-based solution needs to be connected with Enterprise Resource Planning (ERP), CRM or other e-commerce applications. There are so many features to extend the NetSuite functionalities yet users face several issues while integrating it with third-party applications.The application is cloud-based with a differentiated architecture and teams face challenges while integrating it with on-premise legacy applications. Overcoming hybrid world challenges with the archaic coding approach is difficult.

The point-to-point approach requires heavy coding and it is strategically unwise to execute Netsuite API  integration with the help of this approach. As a lot of IT staff are required to brute coding and integrate NetSuite with other systems in an enterprise. Let’s imagine an IT ecosystem where there are thousands and thousands of applications. These applications cannot be integrated with a single NetSuite integration flow.

Image title

There are a lot of disadvantages of integrating NetSuite with this approach:

  1. High operational cost: IT teams use hairball JAVA coding to develop integrations between different endpoints. This method involves a lot of cost, as IT teams need to be hired for building integrations. Also, this method is slow and doesn’t address pervasive integration needs. Teams cannot reuse the integrations and spend huge time on hand coding independent flows.

  2. Technical challenges: Combining new-age technologies is difficult with custom integrations. The integration layer gets disturbed whenever there is a major change in the ecosystem. Huge efforts are required for incorporating minor upgrades. This delays time to revenue and depreciates the quality of services.

  3. Unscalable: Point-to-point coding is not only complex, but it is also unscalable. it cannot be scaled across departments or organizations. NetSuite integration flows are difficult to connect with other partners.

  4. Expensive maintenance: NetSuite integration with a hand-coded approach is costly and requires constant support and maintenance. Maintenance costs spike when developers are required for expensive maintenance. Connectors need to be developed on a timely basis for new integrations.

Integrating NetSuite With Other Applications

NetSuite needs to work in tandem with many other legacy and on-premise applications. While integrating NetSuite with other applications it is important to consider many other factors, i.e., team structures, code bases, architectures, etc. Many organizations still view development with a binary approach where one code is developed and thrown to maintenance team which has a different perspective of integration. NetSuite offers SuiteConnect for integrating NetSuite with enterprise applications. But the set of connectors are limited and make it difficult to integrate with other applications.

To understand the complexity we can take a use case where users needed to write several lines of code just for bringing data from other applications:

In this use case, we will discuss Integrating Salesforce with NetSuite using Java Code (Manual Approach).

Step 1: Go to Remote site settings in Salesforce.

Step 2: Add NetSuite remote URL.

Step 3: Create a Script in NetSuite.

Step 4: Go to Document → Files → SuiteScripts → Manual Script.

Step 5: Create the JavaScript to add a new customer:

// Create a standard NetSuite record
function createRecord(datain) {
    var err = new Object();
    // Validate if mandatory record type is set in the request
    if (!datain.recordtype) {
        err.status = “failed”;
        err.message = “missing recordtype”;
        return err;
    var record = nlapiCreateRecord(datain.recordtype);
    for (var fieldname in datain) {
        if (datain.hasOwnProperty(fieldname)) {
            if (fieldname != ‘recordtype’ && fieldname != ‘id’) {
                var value = datain[fieldname];
                if (value && typeof value != ‘object’) // ignore other type of parameters
                    record.setFieldValue(fieldname, value);
    nlapiLogExecution(‘DEBUG’, ’zip = ’+datain.zip);
    record.setCurrentLineItemValue(‘addressbook’, ’city’, datain.city);
    record.setCurrentLineItemValue(‘addressbook’, ’zip’, datain.zip);
    record.setCurrentLineItemValue(‘addressbook’, ‘country’, ‘US’);
    record.setCurrentLineItemValue(‘addressbook’, ’label’, ’billing address’);
    record.setCurrentLineItemValue(‘contact’, ’contactrole’, ’-10′);
    record.setCurrentLineItemValue(‘contact’, ‘firstname’, datain.firstname);
    var recordId = nlapiSubmitRecord(record);
    nlapiLogExecution(‘DEBUG’, ’id = ’+recordId);
    var nlobj = nlapiLoadRecord(datain.recordtype, recordId);
    return nlobj;

Step 6: Click “Add File” to add a new script.

Step 7: Click Customization → Scripting → Scripts → New. 

Step 8: Select type. Name the created script.

Step 9: Click Save.

A URL is generated that can be used as an endpoint in Salesforce.

Step 10: Click Add Authentication Request, Use Rest call in Salesforce for data transfer (the endpoint will be different for different use cases).

public static void createNSCustomerRecord(account acc) {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        String endpoint = currNetSuiteSettings.NSEndpointCreateCustomer__c;
        string custId;
        //Set Method and Endpoint and Body
        Http http = new Http();
        String responseBody;
        req.setHeader(‘Content - Type’, ’application / json’);
        string NetSuiteProductionAccount = currNetSuiteSettings.NetSuiteProductionAccount__c;
        string NetSuiteProductionUserName = currNetSuiteSettings.NetSuiteProductionUserName__c;
        string NetSuiteProductionPassword = currNetSuiteSettings.NetSuiteProductionPassword__c;
        String authorizationheader = ‘NLAuth nlauth_account = ’+NetSuiteProductionAccount + ’,
            nlauth_email = ’+NetSuiteProductionUserName + ’, nlauth_signature = ’;
        nlauth_email = nlauth_email + NetSuiteProductionPassword;

//Construct Authorization and Content header
req.setHeader(‘Authorization’, authorizationHeader);
string recordType = ‘customer’;
string accountId = ”;
accountId = acc.Id;
system.debug(‘accountId === > ’+accountId);
//you need the minimum field pattern for whatever entity you are posting, refer to their API guide
            recordtype”: ”‘+recordType + '”,”entityid”:”‘+acc.name+'”,
            ”accountId”: ”‘+accountId + '”);
            system.debug(‘setBody’ + req);
            try {
                res = http.send(req);
                responseBody = res.getBody();
                system.debug(‘responseBody’ + responseBody JSONParser parser = JSON.createParser(responseBody);
                    while (parser.nextToken() != null) {
                        System.debug(‘Current token: ‘+parser.getCurrentToken());
                        // Advance to the next value.
                        // Get the field name for the current value.
                        String fieldName = parser.getCurrentName();
                        if (fieldName == ‘id’) {
                            // Get the textual representation of the value.
                            System.debug(‘fieldName == id’);
                            custId = parser.getText();
                            system.debug(‘custId === => ’+custId);
                    try {
                        List < account > acc1 = [select NetSuiteCustomerId__c from account where id = : acc.id];
                        if (acc1.isEmpty() == false) {
                            acc1[0].NetSuiteCustomerId__c = custId;
                            update acc1;
                    } catch (System.CalloutException e) {
                        System.debug(‘Callout error: ‘+e);
                } catch (System.CalloutException e) {

Step 11: Fetch the internal id of customer records in NetSuite and save it in a custom field for future updates.

Step 12: Write batch classes in Salesforce to call the aforementioned function whenever a new account is created.

global class NetSuiteBatchApexWebCalloutClass Implements Database.Batchable < account > , Database.AllowsCallouts {
    global List < account > accountsToTarget;
    private NetSuiteBatchApexWebCalloutClass() {}
    Global NetSuiteBatchApexWebCalloutClass(Set < String > accRecIds) {
        accountsToTarget = [SELECT Id, Name, owner.Name, NetSuiteCustomerId__c FROM Account where Id IN: accRecIds];
    global Iterable < account > start(database.batchablecontext BC) {
        return (accountsToTarget);
    global void execute(Database.BatchableContext BC, List < account > scope) {
        for (Account a: scope) {
    global void finish(Database.BatchableContext info) {} //global void finish loop

There are several dynamic scale and failover issues associated with integrating NetSuite with this approach. This point-to-point coding is complex and problems further expand when organizations have innumerable legacy systems on-premise. The codes should be developed again and again and operations team need to certify them. Several problems resurface when any one connection is moved or updated. Therefore, organizations should have an integration strategy in place for harnessing more power out of NetSuite and similar SaaS-based applications.

Automating NetSuite Integration

A viable solution for NetSuite integration is an automated NetSuite integration tool which marshals technologies in an order and allows teams to integrate cloud and on-premise applications. Here are some of the benefits that come along with it:

Integration Apps: An automated solution enables teams to use custom templates for NetSuite integration. They deliver out-of-the-box functionality to integrate applications.  IT gives a 360-degree view of applications and helps teams in integrating apps in simple steps.

Drives Down Operational Cost: A no-code approach can enable even non-technical business users to build integrations and allow IT teams to focus on governance.

Monitoring and Visibility: An automated solution provides an intuitive interface to monitor and resolve the technology integration issues. This makes maintenance easy and brings greater visibility into the system.

Fosters agility: Business users can build integrations and become easier to do business with. This advantage improves time to revenue and top line profitability.

Breaking Out From Spaghetti Coding: Replacing the Handcoded Approach With Automation

Automation helps teams circumvent the fallacies of spaghetti coding. Advanced tools like Adeptia offer any-to-any integration support to allow NetSuite users achieve 200 times more deployments, 30 times faster recovery, lower failure rate, and 40 times more scalability.

Adeptia's NetSuite connector enables business and non-technical users to connect NetSuite with any target system. Here are some steps that need to be performed in this suite to make NetSuite integration fast and smooth:

Users can replace complex coding effort with simple steps for NetSuite Integration.

Step 1: Log into Adeptia Integration Suite and click "Projects" on Adeptia Interface. The Projects page displays where NetSuite projects appear.

Step 2: Go to Solutions and click "Data Interface." The Data Interface page appears, where any-to-any data flows can be created and interfaces with their name can be viewed.

Step 3: Click "Create Interface." The Create Interface page appears, where the following data elements can be specified: Name, Description, Source Schema Name, Source Schema Type, Source Type, Source Name, Target Name, Target Type, Target Schema Type, Target Schema Name, and Mapping. Data mapping columns can be found here.

Step 4: Map Data is between Source (in the left column) and Target (in the right column), with a drag-and-drop interface.

Here is a video tutorial where you can get a more detailed integration approach.

In this way, normal business users can break down the silos and move NetSuite data with minimum friction. On the other hand, NetSuite integration with a hand-coded approach is brittle and fails to achieve the real purpose. With automation, organizations can set up a future-ready infrastructure that is agile, responsive, secure, and reusable.

enterprise ,integration ,netsuite ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}