https://netsuiteprofessionals.com logo
n

Nicolas Bean

04/11/2022, 2:57 PM
is beforeSubmit always standard? can it ever be dynamic? (the record)
s

Sciuridae54696d

04/11/2022, 3:00 PM
Whether a record is dynamic is decided during - record.load, and record.create. To answer your question, context.newRecord which is part of the beforeSubmit context is also dynamic.
n

Nicolas Bean

04/11/2022, 3:01 PM
oh really ok
I thought it would be standard for some reason
is there documentation somewhere on this?
s

Sciuridae54696d

04/11/2022, 3:03 PM
Actually I take it back, let me run something quickly
you're right, it is standard.
You can test it by checking the context.newRecord.isDynamic, that's a boolean, in my test with the sales order, that was indeed standard.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope Public
 *
 */

define(['N/record','N/runtime'], function(record,runtime) {
  /**
   * @function afterSubmit
   * @description description
   *
   * @public
   * @param  {type} context.newRecord
   * @param  {type} context.oldRecord
   * @param  {type} context.type
   */

   function checkIsDynamic(context){
     log.debug({title:"isDynamic",details:context.newRecord.isDynamic});

   }
  function afterSubmit(context) {
    try{
      var startTime = new Date().getTime();

      checkIsDynamic(context);

    } catch (e) {
      var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
      var scriptId = runtime.getCurrentScript().id;
      var endTime = new Date().getTime();
      log.error("fn:afterSubmit:Error: "+ context.newRecord.type +":"+context.newRecord.id, JSON.stringify(e));
    }
    var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    log.debug('afterSubmit', 'remainingUsage: ' + remainingUsage);
    return true;
  }
   /**
    * @function beforeLoad
    * @description description
    *
    * @public
    * @param  {type} context.newRecord
    * @param  {type} context.type
    * @param  {type} context.form
    * @param  {type} context.request
    * @return {type} - description
    */
   function beforeLoad(context) {
    try{

      checkIsDynamic(context);

    } catch (e) {
      var scriptId = runtime.getCurrentScript().id;
      log.error('ERROR:'+scriptId+':fn.beforeLoad:'+runtime.executionContext, JSON.stringify(e));
    }
    var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    log.debug('beforeLoad', 'remainingUsage: ' + remainingUsage);
    return true;
   }
   /**
    * @function beforeSubmit
    * @description description
    *
    * @public
    * @param  {type} context.newRecord
    * @param  {type} context.oldRecord
    * @param  {type} context.type
    */
   function beforeSubmit(context) {
    try{
      checkIsDynamic(context);
    } catch (e) {
      var scriptId = runtime.getCurrentScript().id;
      log.error('ERROR:'+scriptId+':fn.beforeSubmit:'+runtime.executionContext, JSON.stringify(e));
    }
    var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    log.debug('beforeSubmit', 'remainingUsage: ' + remainingUsage);
    return true;
   }
  return {
    afterSubmit:afterSubmit,
    beforeLoad:beforeLoad,
    beforeSubmit:beforeSubmit
  };
});
message has been deleted
n

Nicolas Bean

04/11/2022, 3:21 PM
that is perfect thank you!
keanu thanks 1
2 Views