Notifications

8 views

Description

When a global variable is declared in an onLoad client script in the global application and tried to access it from another onChange client script in the same global application, it gives a 'variable_name not defined error'.

Below is the example of scripts and the console error:

1] onLoad client script: loadGlobalVariables

var testGlobalVar = {};
function onLoad() {
testGlobalVar.check = 'Load';
console.log('**** Test onLoad => '+testGlobalVar);
}

 

2] onChange client script: onChangeGlobalVariable

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
console.log("### BEFORE ONCHANGE => "+testGlobalVar.check);
testGlobalVar.check = 'Change';
console.log("#### AFTER ONCHANGE => "+testGlobalVar.check);

}

Console Error:

Workaround

Use g_scratchpad.testGlobalVar for accessing global variables across client scripts. The "g_scratchpad" object works fine on a regular form like incident and on Service portal but it doesn't work on Service Catalog Form. An enhancement request is been created to enable g_scratchpad on Service Catalog Form on platform view.

Applicable Versions

Any version

Article Information

Last Updated:2019-05-21 11:59:06
Published:2019-05-17