Synchronize NetSuite Cases with Salesforce Cases > Synchronize NetSuite Cases with Salesforce Cases Recipe Overview > Prerequisites for configuring a script in NetSuite
  

Prerequisites for configuring a script in NetSuite

To synchronize NetSuite cases with Salesforce cases, the following prerequisites must be met:

Configuring a script in NetSuite to subscribe to Case object change

NetSuite connections in Application Integration perform CRUD operations, such as create, read, update, delete on NetSuite tables. When you create or update a Case entity, a web request is initiated in NetSuite. To synchronize NetSuite cases with Salesforce cases, you need to create a script in NetSuite.
To configure a script in NetSuite, perform the following steps:
Step 1: Create a script in NetSuite.
Step 2: Upload the script and create a script record.
Step 3: Deploy the script and apply it to a Case entity.

Creating a script

To create a script, perform the following steps:
    1 Log in to the NetSuite organization.
    2Go to Customization > Scripting > Scripts, and then click New.
    Go to Customization to create a new script in NetSuite.
    3In the Upload Script File section, click the + icon to add a script file. Enter the file name and select the script file as shown in the following image:
    Add a script file.
    Note: Use the .js extension for the script file name.
    For more information about the script format, see Sample script.
    4Click Save.
    5After adding the script file in the Upload Script File section, click Create Script Record.
    6In the Script section, enter the NetSuite event name and ID as shown in the following image:
    NetSuite event name and ID
    7Click Save.
    8In the Script section, click Deploy Script.
    Deploy script
    9You can now apply the script to any Case entity. Enter the deployment script ID and select the Status.
    10Click Save.
    The scrip is successfully deployed.
    Important: The deployed script can be used for any entity in NetSuite, not just the Case entity.
    You can create and add multiple scripts and reuse them.
    You can add multiple scripts and reuse them.

Sample script

You can create a script in NetSuite to automate business processes.
The following snippet is a sample script for NetSuite:

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/https', 'N/log'], function(https, log) {

function afterSubmit(context) {
if (context.type === context.UserEventType.CREATE || context.type === context.UserEventType.EDIT) {
var newRecord = context.newRecord;
var caseId = newRecord.id;
var url = '{CAI process URL}?Input_Case_ID=' + caseId;
try {
var response = https.get({
url: url
});
log.debug({
title: 'GET Request Response',
details: 'Response: ' + response.body
});
} catch (e) {
log.error({
title: 'Error Sending GET Request',
details: e.message
});
}
}
}

return {
afterSubmit: afterSubmit
};
});
Note: You must include the process URL in the script as shown in the sample. Save the file with a .js extension.

Creating a NetSuite ID in the Salesforce Account, Contact, and Case entities

Provide the necessary details in the Account, Contact, and Case entities to create the NetSuite ID in Salesforce.
    1Go to Setup > Build > Customize > Accounts > Fields, and then click New.
    The following image shows the Accounts > Fields option:
    Accounts entity
    2In the Choose Type Field section, select Text Area and click Next.
    3Enter the details in the Field Label, Length, and Field Name fields.
    Enter the field label, length, and field name
    Save the field name for your future use.
    4Click Next. Don't make any change in the other pages.
    5Click Save.
Follow the same steps for the Contact and Case entities.