Scripting Transaction Shipping and Billing Addresses
A transaction's shipping address is stored in an address subrecord linked to a body field. The billing address is stored similarly. Working with these subrecords is similar to working with other body field subrecords. However, there are some differences. For details, see the following sections:
See also About the Address Subrecord.
Addresses Can Be Sourced from Entity Records
Many transactions are associated with an entity. The entity record may already have addresses defined on its Address subtab. When working with a transaction, you can use one of these existing addresses as the shipping or billing address.
If you choose to reference an existing address, your script does not have to create an address subrecord or use any subrecord methods. Instead, you can pick an address with a select field that is associated with the summary field. For example, to designate an existing address as the shipping address on a sales order, you use the shipaddresslist select field. This field identifies the subrecord used by the shippingaddress summary field. For an example of how to select an existing address using the shipaddresslist select field, see Using SuiteScript 2.x to Select an Existing Shipping Address Example.
A Default Address May Be Used
Entities can have default shipping or billing addresses. If you create a transaction without setting a shipping or billing address, the entity's default is used.
To override the default, use removeSubrecord() to clear the summary field before setting your new subrecord values. Alternatively, set the shipaddresslist field to null before setting your new address values. For an example, see Using SuiteScript 2.x to Create a New Shipping Address Example.
New Shipping and Billing Addresses Are Always Custom
When creating a sales order in the UI, you must choose New or Custom in the Ship to Select field to enter a new shipping address. If you select New, the address you enter is also saved to the customer record. If you select Custom, the new address is not saved to the customer record. The address is only saved on the transaction.
In SuiteScript, you don't have the option to choose between New or Custom. Any new shipping or billing address created by your script is treated as a Custom address. The address is saved on the transaction, but it cannot be saved to the entity record.