Home » Deeper in to NetSuite » How to Set a Custom Address in NetSuite Sales Orders using SuiteScript

How to Set a Custom Address in NetSuite Sales Orders using SuiteScript

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 because 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.

CTA - NetSuite Services Banner

One way to avoid this issue is to set a custom address on the NetSuite sales orders, so that it is not added to customer’s address book in NetSuite. To implement this fix, just follow the steps below.

  • First, 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);

  • Next, we’ll set the billing address fields (as shown below).


// 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');

CTA - NetSuite Products
  • 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 the fields for the billing address are prefixed with the term “bill” and similarly all the fields for the shipping address are prefixed with the term “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);

CTA - NetSuite SuiteCommerce Implementation Banner

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');


// 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).

Hope you found this post useful. If you have NetSuite development requirement you would like to discuss, or would like to know more about our NetSuite development services, please get in touch with us.

Get In Touch With Our Experts


    Get In Touch With Our Experts

      I have read and agree to the Privacy Policy of Folio3
      I agree to be contacted by Phone or Email by Folio3

      Get in touch with the

      Award-Winning

      End-to-end NetSuite Servicing Agency

      Tell us how may we assist you!