Make Field mandatory using Client script

PritanjaliG
Tera Contributor

When Caller is System Administrator then service field become mandatory , Contract field should become hidden and Configuration item should become read only 

how to do it using Onchange client script?

 

 

 

 

 

 

 

 

4 REPLIES 4

Bhavya11
Kilo Patron

Hi @PritanjaliG ,

 

Yes you need to write Onchange client script.

To achieve that select user is system administrator or not create Client callable Script include and right logic for that return true if the logged in user is system administrator otherwise false.

To call script include in Onchange client script use GlideAjax.

Depending on the answer mark field mandatory or read-only or hide it.

 

 

Please mark helpful if my answer resolve you question.

 

 

Thanks,

BK

 

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

What's the reason for asking Client Script? Why not UI Policy instead, zero code involved to what you are asking.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @PritanjaliG 

Technically it is best practice, to use the OOTB module to avoid the script. The above requirement you can achieve with UI policies like this

 

AGLearnNGrow_0-1724565296615.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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/atul_grover_lng [ Connect for 1-1 Session]

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

Soni Tushar
Tera Guru

Hello @PritanjaliG ,

 

you should choose UI Policy for this situation because UI Policy is the better choice in this scenario due to its simplicity, performance, and maintainability. Use a Client Script only if there’s a complex logic that UI Policy cannot handle.

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!