Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

strict mode and sharing code between client scripts - how to turn it off for the form?

Rahman3
Tera Expert

Hi Guys,

I have some common code that need to share between couple of client scripts (onChange event). I have created a client script (onLoad) and copied the common code for reuse. But when I use it, I get the error that it can't find the common function. I am thinking its because of the following infomration at the top of the form:

"New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. "

If this is the case how can I disable "Isolate script" only for this form? - Not gobally through system settings. In particular I want to know what this means "configure this form and add the "Isolate script" field."

Stepwise please.

 

Thanks

3 REPLIES 3

Jace Benson
Mega Sage

> Configure this form and add "Isolate Script" field

This means to configure the catalog client script form to show the field "Isolate script".

You cannot disable this on a "per form" basis but rather a "per script" or "for all globally scoped client-side scropts"

Read more about it here: https://hi.service-now.com/kb_view.do?sysparm_article=KB0694479

/*
-- To disable this on a per-script basis, configure 
   this form and add the "Isolate script" field and 
   disable this field.
-- To disable this feature for all new globally-scoped 
   client-side scripts set the system property 
   "glide.script.block.client.globals" to false. If 
   you cannot find this property in your 'System 
   Properties > All Properties' [sys_properties] table, 
   add as follows:
1. Go to sys_properties
2. Click New
3. Populate the form
Name: glide.script.block.client.globals
Type: true|false
Value: false
*/

Sadaf Baig1
Tera Contributor

Hi,

I am getting same error.

New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false.

I am using ServiceNow New York version. I added property and uncheck "Isolate script" field value. but still client script is not working. please suggest me solution.

Anthony53
Tera Contributor

I know this is old, but what I do is on an onLoad I define a function and allocate it to scratchpad.  Like:

g_scratchpad.myFunctionName = function (inputVar) {

*put your code here*

};

 

Then on any other script included, you should be able to use it like g_scratchpad.myFunctionName(inputVar);