It appears subrecords can be treated more or less like normal records (without a save()).
This is an ask to consider making known subrecords a built in part of the related base record, and not require the user to reach into the underlying nsrecord . For example, perhaps an addAddress() to CustomerBase or similar? Here's some code that works as of NFT 4 for some rudimentary NSDAL-style subrecord creation:
/**
* Adds a new shipping address to the given customer based on payload address info
* @param customerid NS internal id for customer
* @param addressInfo order data from the received JSON payload
*/
export function addAddress (customerid, addressInfo: OrderRequestHeader) {
const cust = new Customer(customerid)
const newline = cust.addressbook.addLine()
newline.label = addressInfo.shipTo.address.addressID
const subrecord = new Address(cust.nsrecord.getSublistSubrecord({
sublistId: 'addressbook', fieldId: 'addressbookaddress', line: cust.addressbook.length - 1
}))
const address = addressInfo.shipTo.address
subrecord.addr1 = address.postalAddress.street[0]
subrecord.addr2 = address.postalAddress.street[1]
subrecord.addr3 = address.postalAddress.street[3]
subrecord.addressee = address.postalAddress.deliverTo[0]
subrecord.city = address.postalAddress.city
subrecord.state = address.postalAddress.state
subrecord.zip = address.postalAddress.postalCode
log.debug('populated address subrecord', subrecord)
log.debug('saving customer record', cust.save(true))
return _.toPlainObject(newline)
}
It appears subrecords can be treated more or less like normal records (without a save()).
This is an ask to consider making known subrecords a built in part of the related base record, and not require the user to reach into the underlying
nsrecord
. For example, perhaps anaddAddress()
toCustomerBase
or similar? Here's some code that works as of NFT 4 for some rudimentary NSDAL-style subrecord creation: