Hi all -- working on my first SuiteScript 2.0 scri...
# suitescript
b
Hi all -- working on my first SuiteScript 2.0 script. Attempting to update a phone number in the ship address of a salesorder. I'm getting stuck on the getSublistSubrecord() call. I'm not sure of the fieldId to specify for the shipping address. I'm getting a 'Field shipaddress is not a subrecord field' error when this is run. Much of this code I lifted from the help file. Any guidance would be appreciated!
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define([ 'N/record' ],

    function(record) {

        function afterSubmit(context) {

            var existingRec = context.newRecord;
            var existingID = existingRec.id;

            log.debug({ title: 'existingRecord', details: 'ID: ' + existingID});

            // Load the record.
            var rec = record.load({
                type: record.Type.SALES_ORDER,
                id: existingID,
                isDynamic: false
            });

            var subrec = rec.getSublistSubrecord({
                sublistId: 'addressbook',
                fieldId: 'shipaddress',
                line: 0
            });

            subrec.setValue({
                fieldId: 'addrPhone',
                value: '(888) 349-4660'
            });

            // Save the record.
            try {
                var recId = rec.save();
                log.debug({ title: 'Record updated successfully', details: 'Id: ' + recId });
            } catch (e) {
                log.error({ title: e.name, details: e.message });
            }
        }

        return {
            afterSubmit : afterSubmit
        };
    });