function setCPUshipto(type, name, linenum) { if ...
# suitescript
j
function setCPUshipto(type, name, linenum) { if (name !== "shipmethod" || nlapiGetFieldValue("shipmethod") !== "16853" || nlapiGetFieldValue("location") == "") { return; } var locationId = nlapiGetFieldValue("location"); var locationRec = nlapiLoadRecord("location", locationId); var subrecord = nlapiCreateSubrecord("shippingaddress") || nlapiEditSubrecord("shippingaddress") subrecord.setFieldValue("country", locationRec.getFieldValue("country")); subrecord.setFieldValue("isresidential", "F"); subrecord.setFieldValue("attention", locationRec.getFieldValue("attention")); subrecord.setFieldValue("addressee", locationRec.getFieldValue("addressee")); subrecord.setFieldValue("addr1", locationRec.getFieldValue("addr1")); subrecord.setFieldValue("addr2", locationRec.getFieldValue("addr2")); subrecord.setFieldValue("city", locationRec.getFieldValue("city")); subrecord.setFieldValue("state", locationRec.getFieldValue("state")); subrecord.setFieldValue("zip", locationRec.getFieldValue("zip")); subrecord.commit(); }
b
you would need to change every line that has location rec on it
instead of loading a record using nlapiLoadRecord, you would use one of the search related apis
i recommend nlapiLookupField, its the closest to loading a record
the first 2 parameters to nlapiLookupField are the same as nlapiLoadRecord, its the record type and the internal id of the record
the third parameter is an array of column
normally I would say make the array a list of the field ids
but this will end up being a case where the search columns and record field ids don't match perfectly
this would normally be the part where you have to build the search in the ui to find out column names / use the suitescript record browser
ill save you the trouble, your nlapiLookupField should look like
Copy code
var locationLookup = nlapiLookupField('location', locationId, ['address.countrycode', 'address.attention', 'address.addressee', 'address.address1', 'address.address2', 'address.city', 'address.state', 'address.zip']);
j
so i'm replacing the var locationId = nlapiGetFieldValue("location";
because without edit access, that doesn't work with restricted roles, correct?
b
you would leave the locationId in place
j
ah ok
b
your script won't be able to load the record, but you can get and set the location
just like in the ui
locationLookup should be an Object that looks like
Copy code
{
  "address.countrycode": "US",
  "address.attention": "lorem",
  "address.addressee": "ipsum",
  "address.address1": "dolor,
  "address.address2": "sit",
  "address.city": "amet",
  "address.state": "NY",
  "address.zip": "10007"
}
so you would set the values of the subrecord using values from the locationLookup
j
trying to wrap my head around this while being bombarded with other avatax user questions.. sorry
is this all happening in the same client side script? or do i need to build a saved search that this is referencing?
b
Copy code
subrecord.setFieldValue("country", locationRec.getFieldValue("country"));
should be changed to
Copy code
subrecord.setFieldValue("country", locationLookup['address.countrycode']);
this happens all in the client script. NetSuite will change the 3rd array parameter to nlapiLookupField into search columns
j
i have been swamped with support calls.. thank you for all the above notes.. hoping i'll have time to test in sandbox this afternoon
I finally had time to work on the updates, and it's all working great - thank you! I was able to set their Locations access back to View only and the client script runs just fine.