I'm setting a custom address on a sales order thro...
# suitescript
w
I'm setting a custom address on a sales order through client-script (ss1.0) when I set/change the partner on the order. I'm doing this with the following code:
Copy code
var billfields = [
    'billcountry',
    'billaddress',
    'billattention',
    'billaddressee',
    'billaddress1',
    'billaddress2',
    'billcity',
    'billstate',
    'billzipcode'
    ]
  var billvalues = nlapiLookupField('customer',partnerID,billfields);

  nlapiSetFieldValue("billcountry", billvalues.billcountry, false, true);
  nlapiSetFieldValue("billaddress", billvalues.billaddress,false, true);
  nlapiSetFieldValue("billattention", billvalues.billattention, false, true);
  nlapiSetFieldValue("billaddressee", billvalues.billaddressee, false, true);
  nlapiSetFieldValue("billaddr1", billvalues.billaddress1, false, true);
  nlapiSetFieldValue("billaddr2", billvalues.billaddress2, false, true);
  nlapiSetFieldValue("billcity", billvalues.billcity, false, true);
  nlapiSetFieldValue("billstate", billvalues.billstate, false, true);
  nlapiSetFieldValue("billzip", billvalues.billzipcode, false, true);
  nlapiSetFieldValue("billoverride", 'T', false, true);
  nlapiSetFieldValue("billisresidential", 'F', false, true);
I'm looking at the performance and it takes around a second to set the address. Is there a faster way?
b
w
ok, I could do the following then.
Copy code
var address = nlapiCreateSubrecord('billingaddress');
billfields.forEach(function(billfield){
  address.setFieldValue(billfield, billvalues[billfield]);
});
nlapiSetFieldValue("override", 'T', false, true);
address.setFieldValue('isresidential','F');
address.commit('billingaddress');
I'll try and see if there is a performance difference!
b
expect to use fields like
city
instead of
billcity
w
gotcha!
no forEach then.
hmpf, nlapiCreateSubrecord is not available in client-script.. 😕
b
you can use it, or nlapiEditSubrecord depending on if the subrecord exists already
its only partially complete, for example it doesnt support sublists
which basically means it only works on address subrecords
w
nlapiCreateSubrecord('billingaddress'); only gives me null
is that correct?
b
depends on if the subrecord exists already
if so, you use nlapiEditSubrecord
w
hmm, ok. First I thought it was weird. It's a new record how could a subrecord exist. But it worked ok.
Unfortunately, it was not faster.
message has been deleted
Thanks anyways!