Script Includes with UI Policies and Client Scripts

rchadek
Kilo Contributor

I have a form with multiple UI Policies running scripts and also some onChange Client Scripts that all basically run the same script.

What I'd like to do is be able to store a single script somewhere and then call that from my UI Policies and Client Scripts. This way, if I need to make changes, I only need to do it in one place.

I've looked at Script Includes but from what I understand, that's server-side; while UI Policies and Client Scripts run Client-Side.

Is there anyway to accomplish this?

6 REPLIES 6

Abhinay Erra
Giga Sage

Ryan,



      You can create a script include and call that from client side using GlideAjax. Check this out to learn about GlideAjax. If you need any help in scripting, I can help you out.


GlideAjax - ServiceNow Wiki




Thanks,


Abhinay


Community Alums
Not applicable

When you create your script include, remember to select the 'Client Callable' checkbox so these functions can be used in client script and UI policies.



Cheers,



Tim


Dominik Simunek
Tera Guru

Hi Ryan,



If you want to store client side script only in one place and call it from multiple UI Policies or Client Scripts running on the same table, you can create "On Load Client Script" and place the code there as separate function definition. Then the function is available for other scripts (UI Policy scripts or onChange scripts). This works only if those calling scripts run all on the same table (e.g. incident).



Also read about UI Scripts that allow to store reusable client script.



Cheers,


Dominik


rchadek
Kilo Contributor

Thank you all for your suggestions and rapid responses. I will give it a shot and let you all know how it goes!