Passing Data from beforeSubmit to afterSubmit entry point in NetSuite User Event Scripts

Sometimes you need to capture information before a record is saved and use it after the record is committed. NetSuite’s session object (runtime.getCurrentSession()) makes this easy. You can set values in beforeSubmit and read them back in afterSubmit.

Sample code:

const beforeSubmit = (scriptContext) => {
  try {
    let testObj = { name: 'abcd', age: 25, place: 'kerala' };
    let sessionObj = runtime.getCurrentSession();
    sessionObj.set({
      name: 'customData',
      value: JSON.stringify(testObj)
    });
  } catch (e) {
    log.error('error @ beforeSubmit', e);
  }
};

const afterSubmit = (scriptContext) => {
  try {
    let sessionObj = runtime.getCurrentSession();
    let customDataObj = sessionObj.get({ name: 'customData' });
    log.debug('Retrieved Data', JSON.parse(customDataObj));
  } catch (e) {
    log.error('error @ afterSubmit', e);
  }
};

Leave a comment

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