December 3, 2018

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

March 3, 2021

Does the physical location of a competent employee change the amount of value they can deliver for your organization? If it does, I’d be keen to hear your story. If it does not, why ...

Read More

March 2, 2021

Today a friend and former colleague of mine – who happens to now be in a development leadership role for a NetSuite partner – was lamenting the extreme difficulty of finding and hiring NetSuite ...

Read More

March 1, 2021

Software is never finished; clients are always changing and re-prioritizing. NetSuite is ever a moving target – always updating and evolving. Market forces are always shifting and shoving, forcing new demands on your business. ...

Read More