customRecord not defined SuiteScript 2.0 UE

25 Views Asked by At

Attempting to write a script to pull data from a record into a new record type using an User Event Script. I continue to get an this error: ReferenceError: {custom record type} is not defined at object.afterSubmit.

This is the portion of the code that is failing. This first line is specifically being called out as not defining the custom record. I have it set to the custom record internal ID name.

// Set the value for the 'Name" field customrecord_sample_record_wo_log.setValue({ fieldid: 'name', Value: 'DEL-001'

1

There are 1 best solutions below

0
Krypton On

customrecord_sample_record_wo_log is the ID of the record type, not an instance of the record. To create an instance of the record type you need to use the record.create() method.

var customRecord = record.create({
    type: 'customrecord_sample_record_wo_log'
});

Now you can reference the newly created record as customRecord:

customRecord.setValue({
    fieldId: 'name',
    value: 'DEL-001'
});

Note that record.create assumes you have defined the N/record module as record at the top of your script:

define(['N/record'], function (record) {...}