ExploreConsulting / netsuite-fasttrack-toolkit-ss2

NFT for SuiteScript 2.X
74 stars 20 forks source link

Add first-class subrecord support #11

Closed ShawnTalbert closed 5 years ago

ShawnTalbert commented 5 years ago

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)
  }
ShawnTalbert commented 5 years ago

version 4.3.0 has experimental support for customer.addressbook.addressbookaddress

ShawnTalbert commented 5 years ago

We'll go with the AddressBook subrecord as our exemplar. Open new issues if interested in specific subrecords