user event scripts cannot cause the trigger of another set of user event scripts. While it may seem like a limitation, this is intended to prevent recursive logic from occurring.
For Example, We are creating an Item Fulfillment record on Sales Order creation via User Event script.
There may be multiple user event scripts deployed on Item Fullfillment Record.This may not work for the IF created above.So the solution is to call a suitelet from User Event script for creating the IF.
Sample code.
//User Event Script Deployed On Sales order creation
—————————————————————————
const afterSubmit = (scriptContext) => {
//Checking context is Create
if (scriptContext.type == 'create') {
log.debug('inside user event script');
try {
var newRecord = scriptContext.newRecord;
var soID = scriptContext.newRecord.id;
var iFAutomate = newRecord.getValue('custbody_jj_automate_if_srx_240');
if(iFAutomate == true)
{
// Calling suitelet for creating IF from SO
var output = url.resolveScript({
scriptId: 'customscript_jj_sl_so_if_srx_230',
deploymentId: 'customdeploy_jj_sl_so_if_srx_230',
returnExternalUrl: true
}) + '&soID=' + soID;
var headerObj = {
name: 'Accept-Language',
value: 'en-us'
};
var res = https.post({
url: output,
body: {},
headers: headerObj
});
//Suitelet code
----------------------------------------------
//sales order Id is extracted from suitelet parameter
var salesOrderId = scriptContext.request.parameters.soID; var fulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderId,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true});
fulfillment.setValue({
fieldId: 'shipstatus',
value: 'B' });
fulfillment.save({
enableSourcing: true, //optional, default is false ignoreMandatoryFields: true //optional, defaul is false });
"
"
-----------------------------------------------------------------
User event scripts deployed on IF will be triggered for the IF created via suitelet.