can i write the script in UI Policy?

sreenivassinsta
Tera Contributor

can we write the script in UI Policies, and want to know the example scenario.

1 ACCEPTED SOLUTION

Rajesh Mushke
Mega Sage
Mega Sage
Hi Sreenivas, Yes you can write sctipt in ui policy, find the example below: UI Policy Scripts: UI Policy scripts use the client-side API to execute script logic based on whether the UI Policy condition tests true or false. Use UI Policy scripts to create complex conditional checks or to take actions other than setting field attributes (mandatory, read-only, or visible). The scripting fields for UI Policies are only visible in the Advanced view. To enable the scripting fields, select the Run scripts option. The Execute if true script executes when the UI Policy condition tests true. The Execute if false script executes when the UI Policy condition tests false. Developers can write scripts in one or both script fields depending on the application requirements. Write your script logic inside the onCondition function which is automatically inserted in the scripting fields. The onCondition() function is called by the UI Policy at runtime. There are two script fields. IMPORTANT: The Reverse if false option must be selected for the Execute if false script to run. Although UI Policy Actions execute on all platforms, UI Policy Scripts execute on Desktop/tablet only in the default case. Use the Run scripts in UI type field to select the platform(s) for the UI Policy scripts. Please Refer: https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_scripting_kingston_client_side_scripting/app_store_learnv2_scripting_kingston_ui_policy_scripts?v=kingston Let me know if you need more help. Thanks, Rajashekhar Mushke Community Leader -18


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

View solution in original post

3 REPLIES 3

Rajesh Mushke
Mega Sage
Mega Sage
Hi Sreenivas, Yes you can write sctipt in ui policy, find the example below: UI Policy Scripts: UI Policy scripts use the client-side API to execute script logic based on whether the UI Policy condition tests true or false. Use UI Policy scripts to create complex conditional checks or to take actions other than setting field attributes (mandatory, read-only, or visible). The scripting fields for UI Policies are only visible in the Advanced view. To enable the scripting fields, select the Run scripts option. The Execute if true script executes when the UI Policy condition tests true. The Execute if false script executes when the UI Policy condition tests false. Developers can write scripts in one or both script fields depending on the application requirements. Write your script logic inside the onCondition function which is automatically inserted in the scripting fields. The onCondition() function is called by the UI Policy at runtime. There are two script fields. IMPORTANT: The Reverse if false option must be selected for the Execute if false script to run. Although UI Policy Actions execute on all platforms, UI Policy Scripts execute on Desktop/tablet only in the default case. Use the Run scripts in UI type field to select the platform(s) for the UI Policy scripts. Please Refer: https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_scripting_kingston_client_side_scripting/app_store_learnv2_scripting_kingston_ui_policy_scripts?v=kingston Let me know if you need more help. Thanks, Rajashekhar Mushke Community Leader -18


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Sourabh26
Giga Guru

Hi,

 

Yes you can write the script in the UI policies but it is not considered as a BEST Practice.

If you want to make a fields as Mandatory or Read Only or Visible then go for UI Policy and add the appropriate UI Action other than that if you want to perform any Form Validations then go for Client Script.

 

Although, if you wanna write the script in the UI Policy then there is a Section as "Script". Under that there is a field as "Run Script". Select it, now you will see the area under which you can write your script.

 

Remember there are 2 different section for script:

1) Execute If True - Runs when the condition specified in the UI Policy matches

2) Execute If False - Runs when the condition specified in the UI Policy does not match.

 

Please Mark It as Helpful if you find the above information as Correct.

 

Regards,

Sourabh

Community Alums
Not applicable

Yes, you can write, one of the scenario is to hide a related list based on condition