Can you have a global variable in a script include that can be used in all of your functions?

Dave65
Tera Contributor

Can you have a global variable in a script include that can be used in all of your functions?

I want to have a Global variable that controls logging for the functions. I don't want to have the same variable in each function. I want 1 location to set it.

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hi @Dave

Follow below link:

How to access global variable in catalog client scripts?

Global variables declared on onLoad client script are not accessible from another onChange client sc...


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

Aman

Thank you for your quick response. I made an error in my question. I want to create a global variable in a Script Include, not a client script.

I had tried before with:

var logging = true;

inside the Initialize function but that didn't work.

Hi,

You can create script include with variables values and  you can use it in server/client side script.

Take  a look at  -  Scripting 101: Script Includes - Class vs Classless

 

Also, another option for script include, may be you can assigned the value in system property and you can use it server side script.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Classless functions are pretty straightforward, you create them with the same name as class and it can be called from any Server side script.

You can check below article:

Scripting 101: Script Includes - Class vs Classless

Global objects and variables

For Global variable, have a look at IncidentState script include which comes OOB, for reference how to create Global variables.

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar