3

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
gregpymm
  • 33
  • 1
  • 3

1 Answers1

4

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); 
bknights
  • 14,408
  • 2
  • 18
  • 31
  • Thanks. Your first code snippet works for us for updating a record, (which gives us an interim solution) but we cannot get it to work when initially creating the record with nlapiCreateRecord. Any thoughts? – gregpymm Dec 16 '15 at 21:59
  • You would generally create the sales order with: `var soRec = nlapiTransformRecord('customer', custId, 'salesorder');` That will allow you to set the shipaddresslist from the customer's addresses. If for some reason you can't do that then you can do `nlapiCreateRecord('salesorder', {recordmode:'dynamic'})` and that will allow you to do the same as long as you do `soRec.setFieldValue('entity', custId);` before you try to set the address. IMO dynamic mode is usually more trouble than it's worth. – bknights Dec 16 '15 at 23:36
  • Thanks. We will give it a try on our next pass... The solution that worked for us was to reload the record we just created then doing soRec.setFieldValue('shipaddresslist', addressID); to set the shipping address. – gregpymm Dec 17 '15 at 22:08
  • @bknights Hi, I need to set custom address on sales order. I set 'shipaddresslist' as null and trying, but it is not working. Any suggestion ? I am using after submit event. – YNK Mar 20 '20 at 14:48