Defaulting Item Line Field to Blank in Non-User Interface Contexts: User Event Script Before Submit

Setting Default Blank Value for Item Line Field in Sales Order across Non-User Interface Contexts Using User Event Script Before Load.

In scenarios where a Sales Order (SO) is generated outside the user interface, the designated line field will automatically default to a null value.

const beforeSubmit = (scriptContext) => {
            log.debug("Execution Context:", runtime.executionContext);
              if(scriptContext.type == scriptContext.UserEventType.CREATE){
                log.debug("CREATE MODE");
                if(runtime.executionContext !== 'USERINTERFACE'){
                  log.debug("Execution Context is not UI");
                  var currentRecordObj = scriptContext.newRecord;
                  var lineCount = currentRecordObj.getLineCount({
                      sublistId : 'item'
                  })
                  for(var j = 0; j < lineCount; j++){
                      var createPO = currentRecordObj.setSublistValue({
                          sublistId: 'item',
                          fieldId: 'createpo',
                          line : j,
                          value: "",
                      });
                  }  
              }
                else{
                  log.debug("Execution Context is UI");
                }
            }
              else{
                  log.debug("NOT CREATE MODE")
              }
          }
        

        return {beforeSubmit}
    });

Leave a comment

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