Attach a User Note to a Custom Record Without Hardcoding the Record ID

record.create({ type: record.Type.NOTE })
.setValue('note', noteText)
.setValue('record', customRecordId)
.setValue('recordtype', 'customrecord_abc_123')
.save();

The above code throws an error

You have entered an Invalid Field Value customrecord_abc_123 for the following field: recordtype

SOLUTION

SuiteQL offers a CustomRecordType table [II] which you can query to get the internal ID of a custom record:

let customRecordType = query.runSuiteQL({
query:
SELECT internalid FROM CustomRecordType WHERE scriptid = 'CUSTOMRECORD_ABC_123'
// Note: The scriptid must be UPPERCASE
}).asMappedResults()[0].internalid;

record.create({ type: record.Type.NOTE })
.setValue('note', noteText)
.setValue('record', customRecordId)
.setValue('recordtype', customRecordType)
.save();

Leave a comment

Your email address will not be published. Required fields are marked *