Skip to main content

Netsuite address creation

A step-by-step guide on using custom entity fields and a workflow action script to seamlessly integrate external bot data into the native NetSuite address book.

Updated over a week ago

Setting up addresses in NetSuite via external bots isn't always straightforward because native Address Book sublists are difficult to map directly. This guide provides a simple workaround: we create standard custom fields for the bot to easily fill out, and a background script automatically transfers that data into the proper NetSuite Address Book format.

1. In NetSuite > Customization > List, Record and Fields > Entity Fields > New, create custom fields for address lines (like Street, City, State, Zip). In our example, we used the following field names:

custentity37 - street

custentityecity - city

custentity_estate - state

custentity_ezip - zip

2. Update the provided script with these custom field names marked yellow and save it in a file with .js extension.

/**
* @NApiVersion 2.1
* @NScriptType WorkflowActionScript
* @NModuleScope Public
*/

define(["N/record", "N/runtime"], function (N_record, N_runtime) {
"use strict";

function onAction({ newRecord: { id, type } }) {
log.debug("workflow set address", { id, type });

const employee = N_record.load({ id, type, isDynamic: true });

const address = {
addr1: employee.getValue({ fieldId: "custentity37"🟨 }),
city: employee.getValue({ fieldId: "custentityecity"🟨 }),
state: employee.getValue({ fieldId: "custentity_estate"🟨 }),
zip: employee.getValue({ fieldId: "custentity_ezip"🟨 }),
};

log.debug("address", address);

var currentAddressCount = employee.getLineCount({
sublistId: "addressbook",
});

if (currentAddressCount === 0) {
employee.selectNewLine({
sublistId: "addressbook",
});
} else {
employee.selectLine({
sublistId: "addressbook",
line: 0,
});
}

var addressSubrecord = employee.getCurrentSublistSubrecord({
sublistId: "addressbook",
fieldId: "addressbookaddress",
});

addressSubrecord.setValue({
fieldId: "addr1",
value: address.addr1,
});

addressSubrecord.setValue({
fieldId: "city",
value: address.city,
});

addressSubrecord.setValue({
fieldId: "state",
value: address.state,
});

addressSubrecord.setValue({
fieldId: "zip",
value: address.zip,
});

employee.commitLine({
sublistId: "addressbook",
});

employee.save();

return 1;
}

return { onAction };
});

Deploying the script in your environment

Follow these steps to deploy the script in NetSuite:

  1. Upload your .js file to the File Cabinet.

2. On the Upload Script File page, click the + icon to pick the script from your PC, or select the script from the dropdown if it's already uploaded to NetSuite. Click the Create Script Record button.

3. Set the Name (e.g., Set Address) and ID (e.g., _set_address) for your script record. Click Save.

4. Click the Deploy Script button at the top of the page.

5. On the Script Deployment page, configure the following:

  • Applies To: Select Customer (filling in the ID field is optional).

  • Status: Set to Released.

  • Roles: Check the Select All box to choose all roles.

  • Click Save.

6. Script logs are visible under the Execution Log tab on the Script record. Make sure you have the 'Debug' log level set in your script deployment to see them.

Creating the Workflow

Create a workflow that will trigger the script upon Record Creation:

  1. Navigate to Customization > Workflow > Workflows > New.

2. Set up your basic workflow properties (Name, Record Type, Sub Types, etc.) and set Initiation to Event Based (on Create).

3. Go to State 1 > New Action.

4. Select the Custom Action script that you have just added (it will appear under the name of your file or the script name you defined in NetSuite).

Note: You might want to add Workflow conditions to execute this action only when the custom Customer-level address fields are not empty (as they will be prefilled by the bot).

Mapping in altaFlow

In altaFlow, map the custom fields you created to the bot. Now, the bot will send the address data directly to these custom fields, and your newly deployed Workflow Action Script will automatically propagate them to the actual NetSuite Address Book.

Did this answer your question?