Hello! I'm using Workflow Action script to add new...
# suitescript
j
Hello! I'm using Workflow Action script to add new line address in Lead record afterSubmit, but unfortunately the subrecord is not added on the Lead record. Any idea why?
s
The error is in the script type
Perhaps the client script is more suitable
j
Oh, you mean I cannot use WFA script for subrecords?
s
That's right. Even because this type of script does not exist. At least, it doesn't exist in the documentation.
j
Thanks! Will try to transfer my logic in client script.
n
message has been deleted
w
You can add subrecords in workflow actions. You will need to save the leadRec record. However .save() is not permitted on in the workflow action context, so you will need to load the record and use the scriptContext.newRecord to reference the ID ^ record type
👍 2
s
@NElliott This one I didn't know! thank you for the information
👍 1
w
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType workflowactionscript
 */
define(['N/record'], function (record) {
    function onAction(scriptContext) {
        var leadRec = record.load({
            type: scriptContext.newRecord.type,
            id: scriptContext.newRecord.id,
            isDynamic: true,
        })
        leadRec.selectNewLine({
            sublistId: 'addressbook'
        });
        leadRec.setCurrentSublistValue({
            sublistId: 'addressbook',
            fieldId: 'defaultshipping',
            value: true
        });
        leadRec.setCurrentSublistValue({
            sublistId: 'addressbook',
            fieldId: 'label',
            value: 'Default Shipping'
        });
        var myAddressSubRecord = leadRec.getCurrentSublistSubrecord({
            sublistId: 'addressbook',
            fieldId: 'addressbookaddress'
        });
        myAddressSubRecord.setValue({
            fieldId: 'country',
            value: 'US'
        });
        myAddressSubRecord.setValue({
            fieldId: 'city',
            value: 'San Mateo'
        });
        myAddressSubRecord.setValue({
            fieldId: 'state',
            value: 'CA'
        });
        myAddressSubRecord.setValue({
            fieldId: 'zip',
            value: '94403'
        });
        myAddressSubRecord.setValue({
            fieldId: 'addr1',
            value: '2955 Campus Drive'
        });
        myAddressSubRecord.setValue({
            fieldId: 'addr2',
            value: 'Suite 100'
        });
        leadRec.commitLine({
            sublistId: 'addressbook'
        })
        leadRec.save();
    }
    return {
        onAction: onAction
    };
});
j
Will give this a try @Webber. Thank you!
I tried this, but it didn't work. Have you tried this in your test account?
w
oops i forgot to add the leadRec.save() command
👀 1
j
Yah! That's it! Thank youuu!