Reputation: 945
I am trying to get the default shipping and billing addresses for a customer in SuiteScript.
var shipaddress = null;
var billaddress = null;
//Find the default billing and shipping addresses
var add_Count = customerRec.getLineCount('addressbook');
for (var i = 1; i <= add_Count; i++){
customerRec.selectLine('addressbook', i);
var def_Bill = customerRec.getCurrentSublistValue('addressbook', 'defaultbilling');
var def_Ship = customerRec.getCurrentSublistValue('addressbook', 'defaultshipping');
if(def_Bill){
billaddress = customerRec.getCurrentSublistSubrecord('addressbook', 'addressbookaddress');
} else if(def_Ship){
shipaddress = customerRec.getCurrentSublistSubrecord('addressbook', 'addressbookaddress');
}
}
With this code I am able to get the first one, but as soon as it hits
customerRec.selectLine('addressbook', i);
for the second time it throws the error.
SSS_INVALID_SUBLIST_OPERATION
You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.
Upvotes: 2
Views: 2648
Reputation: 945
I found an answer. Please see below.
var add_Count = customerRec.getLineCount('addressbook');
for (var i = 0; i < add_Count; i++){
var def_Bill = customerRec.getSublistValue('addressbook', 'defaultbilling', i);
var def_Ship = customerRec.getSublistValue('addressbook', 'defaultshipping', i);
var anAddress = customerRec.getSublistSubrecord('addressbook', 'addressbookaddress', i);
if(def_Bill){
billaddress = anAddress;
} else if(def_Ship){
shipaddress = anAddress;
}
}
Upvotes: 5