make Requested by variable Readonly for End users

prasad39
Tera Contributor

Hi All, 

 

I have requirement like,

I have a 'requested by' varaible Reffering to user table, Currently this variable is editable for all the users. users is asking 'requested by' variable is editable only for 'ITIL' role users for other users it should be Readonly. Can any one help me on this.

 

Thanks, 

Prasad 

1 ACCEPTED SOLUTION

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @prasad39 

 

You can use catalog client script.

 

https://www.servicenow.com/community/developer-forum/set-variable-to-read-only-based-on-role/m-p/162...

LearnNGrowAtul_0-1705584255329.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]

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

View solution in original post

5 REPLIES 5

Anand Kumar P
Giga Patron
Giga Patron

Hi @prasad39,

Write onloadcatalog client script with below script 

// Check if the user has the ITIL role
if (g_user.hasRoleExactly('itil')) {
// If user has ITIL role, make the "Requested by" field editable
g_form.setReadOnly('requested_by', false);
} else {
// If user doesn't have ITIL role, make the "Requested by" field readonly
g_form.setReadOnly('requested_by', true);
}
}

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand