script include from ui policy

tushar_ghadage
Tera Contributor

Hi Everyone, 

Can we call script include from UI Policy ...? and if yes how and does calling script include from Ui policy make no sence ..?

 

thanks 

 

8 REPLIES 8

The syntax will remain the same; you just need to add it in the script section.

There are examples in the link above—just follow them. The script syntax remains the same.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Bhavya11
Kilo Patron

Hi @tushar_ghadage ,

 

You can use glideajax.

The GlideAjax class allows the execution of server-side code from the client. GlideAjax calls pass parameters to the script includes, and, using naming conventions, allows the use of these parameters.

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

Maheshwari Mano
Tera Contributor

Hi @tushar_ghadage ,

 

 

Yes, you can call a Script Include using GlideAjax, similar to how it’s done in a Client Script.

Enable the Run scripts checkbox and add the code under Execute if true or Execute if false, based on your requirement.

 

Sample code:

var ga = new GlideAjax('MyAjaxSI');
ga.addParam('sysparm_name', 'getStatus');
ga.getXMLAnswer(function(answer) {
if (answer === 'active') {
g_form.setMandatory('u_field', true);
}
});

Ankur Bawiskar
Tera Patron

@tushar_ghadage 

Yes in "Execute if true" or "Execute if false" you can call script include using GlideAjax

UI policies are used for simple requirement based on fields etc to show/hide, make fields editable/mandatory

If you are planning to use script then better use Client Script

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader