
petercawdron
Kilo Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-18-2019 06:06 PM
There's a really nice, simple trick to getting Catalog Client Script to run in both the portal and the back end of ServiceNow and that's by adding the prefix variables whenever the script is running on a regular form.
First, you need to set your scripts so they apply on the target record.
Then, within your scripts, add the following three lines to get the prefix required. This will allow the script to self-adjust when it runs, catering for whether it's within the portal or in the back end.
//gains access to the global window object regardless of script isolation or otherwise
var myWin = (0, eval)('this');
//this allows the script to distinguish between when it is running in the portal as opposed to the back end (where the prefix variables. is needed)
var thisPage = myWin.location.href.indexOf('.do')==-1;
var prefix = thisPage ? '' : 'variables.';
//EXAMPLE
//by including prefix+ before your g_form references you can ensure your script will run in both places
if(g_form.getValue(prefix+'u_employment_end_date')==''){
g_form.setDisplay(prefix+'reason',false);
console.log('%cEnd date not set','color:navy');
return;
}
Have fun
Labels:
- 1,151 Views