For a few customers the addressbook does not exist...
# suitescript
e
For a few customers the addressbook does not exist and this returns -1.
Copy code
const lineNumber = objRecord.findSublistLineWithValue({
	sublistId: 'addressbook',
	fieldId: 'defaultbilling',
	value: true,
});
I would like to add a default address. How can I do that. Do I need to create the addressbook some how?
b
do you want to make an existing address the default billing address
e
No. I want to add a new address that will be set as "Default billing address"
b
add a new line to the addressbook sublist
set the defaultbilling field to true
create an address subrecord on the addressbookaddress field of the addressbook sublist
expect to understand how SuiteScript 2.0 Scripting Subrecords work
e
Thanks @battk 🙂 I will try that
I tried this, but it fails with: USER_ERROR "Please enter value(s) for: Address".
Copy code
if (lineNumber === -1) {   
  var addressCount = objRecord.getLineCount({'sublistId': 'addressbook'});

  objRecord.insertLine({sublistId: "addressbook", line: addressCount});

  var adrObj = objRecord.setSublistValue({sublistId: "addressbook", line: addressCount, fieldId: "defaultbilling", value: true});

  adrObj.setValue({fieldId: 'city', value:'Test'});
  adrObj.setValue({fieldId: 'country', value:'NO'});
  adrObj.setValue({fieldId: 'addr1', value: 'Test'});

  objRecord.save();
}
b
i wouldnt recommend using insertLine
just set values on the line you want to add
that said, you need to go through that subrecord documentation i linked
there are specific methods used to get subrecords
they all have subrecord in the name
e
Ok, thanks for helping 🙂 Its working now 👍 So after I set the sublist with:
setSublistValue
I cant use the return value. I need to use
getSublistSubrecord
before setting values. That was not clear to me after reading the API doc.
s
With NFT:
👍 1