In the previous discussion, we introduced the concept of the afterSubmit function and its role in NetSuite's User Event Script Type. Now, let's delve into a practical example demonstrating how this function can be utilized to transform records efficiently.
This sample code elaborates how you can generate an invoice after a sales order is created automatically:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record'],
/**
* @param{record} record
*/
(record) => {
/**
* Defines the function definition that is executed after record is submitted.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum