3
votes

When creating a Sales Order in NetSuite via Suitescript, we can successfully set the "Ship To" (Field ID: shipaddress) by sending it a string containing a full address.

This causes a problem because the "SHIP TO SELECT" dropdown field retains the default address set on the customer.

Ideally we would rather send in the valid ID from the Customer record and set the dropdown "SHIP TO SELECT" (Field ID: shipaddresslist) field using that ID.

We can get the valid ID, but cannot find a way to set that ID on the field in order to populate that dropdown.

1
nalpiSetFieldValue('shipaddresslist', VALID_ID) doesn't that works?prasun

1 Answers

3
votes

Generally if you do this outside the context of a User Event Before Submit script you also need to make sure you save with sourcing.

var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', addressId);
nlapiSubmitRecord(soRec, true); 
// alternatively nlapiSubmitRecord(soRec, {enablesourcing:true [, disabletriggers:true|false, ignoremandatoryfields:true|false]});

If you are still seeing the old address text you might add:

soRec.setFieldValue('shipaddress', null);

before submitting.

If what you want to do is set a custom address then similar but you need to set the override:

var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', null);
soRec.setFieldValue('shipoverride', 'T');
soRec.setFieldValue('shipaddress', formattedAddressString);
nlapiSubmitRecord(soRec); 

Be warned though that doing this will make any searches or automation that rely on address fields miss or produce incorrect results around this record.

If you want a custom address you are generally better off:

var soRec = nlapiLoadRecord('salesorder' soId);
soRec.setFieldValue('shipaddresslist', null);
soRec.setFieldValue('shipaddr1', '123 Elm St.');
soRec.setFieldValue('shipcity', 'Portland');
...
nlapiSubmitRecord(soRec);