Wednesday, March 27, 2019

Determining the access mode in Client Scripts is visible only in the pageInit function

Access modes determine the mode in which the record is being accessed (whether it is from create, copy, edit, etc.). When writing a Client SuiteScript, the access mode is passed through the clientPageInit(type) functions as the parameter "type". But, this is not readily visible to other functions.

To address this issue, a global variable can be created to store the value of the access mode when the clientPageInit function is called.
An example would be the following code:

var accessMode; //declare the global variable outside the other functions

function clientPageInit(type){
   accessMode = type; //assign the value of the access mode to the global variable
}


Since the variable accessMode is a global variable, it can be accessed anywhere in the code. For example, to use this in the clientFieldChanged function, the code would look something like below:

clientFieldChanged(String, String, Number){
 if(accessMode=='edit'){
  // .... perform operations here
 }
}

No comments:

Post a Comment