One of the most common problems faced by NetSuite users when synchronizing orders from third party ecommerce or EDI systems into NetSuite is the extremely cluttered customer address book you end up with in NetSuite, at the end of the order import process. Since the address book for customers with numerous sales orders tends to have a lot of redundant addresses, which ultimately results in degraded performance, when querying that specific customer record (for viewing or updating, etc.) in NetSuite.
The reason for that is that whenever that particular customer record is viewed in NetSuite, NetSuite loads the entire address book for that customer, so if his address book has a long list of (redundant) addresses, it obviously takes more time to load the customer record before it is available for viewing or update purposes.
One way to avoid this issue is to set a custom address on NetSuite sales orders so it is not added to the customer’s address book. To implement this fix, just follow the steps below.
Steps for Setting a Custom Address in NetSuite Sales Orders Using SuiteScript
Sometimes, businesses need to assign a custom shipping or billing address to a sales order instead of using the default customer address. In NetSuite, this can be done efficiently using SuiteScript 2.0.
Step 1: Load the Sales Order Record
Use record.load to access the sales order you want to modify. Let’s load a sales order with a specified internal id from NetSuite. In the below example below, 304 is the sales order’s internal ID.
// load sales order record
var salesorder = nlapiLoadRecord("salesorder", 304);
Step 2: Set the Custom Address
NetSuite stores addresses in subrecords on the sales order. To set a custom address:
Use
// set billing details
salesorder.setFieldValue('billcountry', 'US');
salesorder.setFieldValue('billisresidential', 'F');
salesorder.setFieldValue('billattention', 'Billing Address');
salesorder.setFieldValue('billaddressee', 'NetSuite Inc.');
salesorder.setFieldValue('billaddrphone', '(123)456-7890');
salesorder.setFieldValue('billaddr1', '2955 Campus Drive');
salesorder.setFieldValue('billaddr2', 'Suite - 100');
salesorder.setFieldValue('billcity', 'San Mateo');
salesorder.setFieldValue('billstate', 'CA');
salesorder.setFieldValue('billzip', '94403');billingaddress subrecord if you want to modify the billing address. You can set multiple fields: addr1, addr2, city, state, zip, country.
- After that we’ll set the same fields for the shipping address (as depicted below).
// set shipping details
salesorder.setFieldValue('shipcountry', 'US');
salesorder.setFieldValue('shipisresidential', 'F');
salesorder.setFieldValue('shipattention', 'Shipping Address');
salesorder.setFieldValue('shipaddressee', 'NetSuite Inc.');
salesorder.setFieldValue('shipaddrphone', '(123)456-7890');
salesorder.setFieldValue('shipaddr1', '2955 Campus Drive');
salesorder.setFieldValue('shipaddr2', 'Suite - 100');
salesorder.setFieldValue('shipcity', 'San Mateo');
salesorder.setFieldValue('shipstate', 'CA');
salesorder.setFieldValue('shipzip', '94403');
As you can see from the code snippets above, all fields for the billing address are prefixed with “bill”, and similarly, all fields for the shipping address are prefixed with “ship”.
- Once you have completed the above steps, you can just submit the sales order record (by using the command below).
// submit sales order
nlapiSubmitRecord(salesorder);
Note
One of the most important things to remember when scripting addresses in NetSuite is that the ‘country’ field determines which address form is used. So if you are running your script in dynamic mode, you must set the ‘country’ field first.
Here’s the complete source code for this fix.
// load sales order record
var salesorder = nlapiLoadRecord("salesorder", 304);
// set billing details
salesorder.setFieldValue('billcountry', 'US');
salesorder.setFieldValue('billisresidential', 'F');
salesorder.setFieldValue('billattention', 'Billing Address');
salesorder.setFieldValue('billaddressee', 'NetSuite Inc.');
salesorder.setFieldValue('billaddrphone', '(123)456-7890');
salesorder.setFieldValue('billaddr1', '2955 Campus Drive');
salesorder.setFieldValue('billaddr2', 'Suite - 100');
salesorder.setFieldValue('billcity', 'San Mateo');
salesorder.setFieldValue('billstate', 'CA');
salesorder.setFieldValue('billzip', '94403');
// set shipping details
salesorder.setFieldValue('shipcountry', 'US');
salesorder.setFieldValue('shipisresidential', 'F');
salesorder.setFieldValue('shipattention', 'Shipping Address');
salesorder.setFieldValue('shipaddressee', 'NetSuite Inc.');
salesorder.setFieldValue('shipaddrphone', '(123)456-7890');
salesorder.setFieldValue('shipaddr1', '2955 Campus Drive');
salesorder.setFieldValue('shipaddr2', 'Suite - 100');
salesorder.setFieldValue('shipcity', 'San Mateo');
salesorder.setFieldValue('shipstate', 'CA');
salesorder.setFieldValue('shipzip', '94403');
Step 3: Save the Record
// submit sales order
nlapiSubmitRecord(salesorder);
This fix is for the Edit Sales Order scenario only. In my next post, I’ll show you how to implement this fix in the Create Sales Order scenario. The solution remains the same even in that scenario but may be additional information that may need to add, in order to create a sales order in NetSuite (for e.g. the customer and line items).
Conclusion
Setting a custom address on NetSuite sales orders using SuiteScript 2.0 gives businesses full control over shipping and billing information. By leveraging subrecords for shippingaddress or billingaddress, you can automate updates, reduce manual errors, and ensure orders reflect the correct customer information. This approach is especially useful for companies with multiple shipping locations, dropshipping operations, or unique customer requirements.
Want to streamline your NetSuite sales order process with automated custom addresses? Our NetSuite SuiteScript experts can help you implement NetSuite reliable scripts, manage subrecords efficiently, and optimize your order workflows.
Contact us today to automate your order management and improve operational accuracy.