Subrecord Sneak Peek

I’m wrapping up my preparation for recording the subrecord content today. Here’s a sneak peek at some of the code you’ll see. This is a User Event script that will automatically add the main Company address to every new Employee record:

function beforeSubmit(context) {
    log.audit({title: "Adding company address..."});

    addCompanyAddress(context.newRecord, getCompanyAddress());

    log.audit({title: "Company address added."});

function getCompanyAddress() {
    log.audit({title: "Retrieving company address..."});

    var companyInfo = config.load({
        type: config.Type.COMPANY_INFORMATION

    var companyAddress = companyInfo.getSubrecord({fieldId: "mainaddress"});

    return {
        addr1: companyAddress.getValue({fieldId: "addr1"}),
        addr2: companyAddress.getValue({fieldId: "addr2"}),
        addr3: companyAddress.getValue({fieldId: "addr3"}),
        city: companyAddress.getValue({fieldId: "city"}),
        country: companyAddress.getValue({fieldId: "country"}),
        state: companyAddress.getValue({fieldId: "state"}),
        zip: companyAddress.getValue({fieldId: "zip"})

function addCompanyAddress(rec, address) {
    log.audit({title: "Creating new subrecord..."});

    rec.insertLine({sublistId: "addressbook", line: 0});

    var newAddress = rec.getSublistSubrecord({
        sublistId: "addressbook",
        fieldId: "addressbookaddress",
        line: 0

    newAddress.setValue({fieldId: "country", value:});
    newAddress.setValue({fieldId: "state", value: address.state});
    newAddress.setValue({fieldId: "city", value:});
    newAddress.setValue({fieldId: "zip", value:});
    newAddress.setValue({fieldId: "addr1", value: address.addr1});
    newAddress.setValue({fieldId: "addr2", value: address.addr2});
    newAddress.setValue({fieldId: "addr3", value: address.addr3});

My challenge to you is to read/learn as much as you can from the code alone. What questions do you have? What is unclear from the code? Anything jump out at you?

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Related posts

January 7, 2021

Anything I wrote today about business would both feel and be inadequate. I simply can’t arrive at the words to express how I feel in this moment. So instead, here are a few helpful ...

Read More

December 20, 2020

2020 was a hundred swift kicks to the shorts and one giant kick in the ass. If you’ve lost people you love, if you’ve gotten sick or hurt, if you’ve lost your job, if ...

Read More

December 16, 2020

“I’ve been meaning to learn SuiteScript, but it’s hard to find the time …”“We’re slammed, and I just don’t have the time …”“I haven’t made the time …” All are variations of a theme ...

Read More

December 14, 2020

Last week we looked at mimicking the functionality of a REST endpoint with its own module (e.g. retrieving a User, or a list of Users, refreshing a token, etc). For complex integrations that rely on a large ...

Read More