Addresses are saved as sub records in NetSuite. The sublist is called “addressbook” and is indexed by “addressbookaddress”.Here are the standard fields in the sublist for “addressbook”.
Label – not unique and if omitted becomes Address Line 1
defaultbilling – must be unique to one address
defaultshipping – must be unique to one address
isresidential – can apply to any or all addresses
Under each address is a subrecord that contains these fields:
Attention
Addressee
Address Line 1
Address Line 2
Address Line 3
City
State
Zip
Any custom fields that you’ve created
Here is a code example that demonstrates how to update addresses. The variable “line” corresponds with a zero-based index of the address as it appears in the Address tab under a customer. The variable “customer_id” is the internal ID of the customer and all assigned values are coming from variables which you’d set prior to running this code.
It is better to load record in static mode to deal with addresses.
Sample code snippet for adding an address to the the address subrecord.
{
var rec = record.load({
type: record.Type.CUSTOMER,
id: customer_id,
isDynamic: false
});
rec.insertLine({
sublistId: 'addressbook',
line: 0
});
line = 0;
}
/**
* Modify those fields present in the Address sublist lines
*/
rec.setSublistValue({
sublistId: 'addressbook',
fieldId: 'defaultbilling',
value: defaultbilling,
line: line
});
rec.setSublistValue({
sublistId: 'addressbook',
fieldId: 'defaultshipping',
value: defaultshipping,
line: line
});
/**
* Load the sublist record, which holds all the actual address fields
*/
var subrec2 = rec.getSublistSubrecord({
sublistId: 'addressbook',
fieldId: 'addressbookaddress',
line: line
});
/**
* Modify all subrecord fields
*/
subrec2.setValue({
fieldId: 'attention',
value: attention
});
subrec2.setValue({
fieldId: 'addressee',
value: addressee
})
subrec2.setValue({
fieldId: 'addr1',
value: addr1
});
subrec2.setValue({
fieldId: 'addr2',
value: addr2
});
subrec2.setValue({
fieldId: 'addr3',
value: addr3
})
subrec2.setValue({
fieldId: 'city',
value: city
});
subrec2.setValue({
fieldId: 'state',
value: state
});
subrec2.setValue({
fieldId: 'zip',
value: zip
});
/**
* Save the record
*/
rec.save()