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

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]

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

Anil Lande
Kilo Patron

Hi,

One way is to make it readonly at Variable configuration level.

Screenshot 2024-01-18 at 6.52.49 PM.png

Or use OnLoad client script to make it readonly.

you can use below logic:

 

 

if(g_user.hasRoleExactly('itil')){
g_form.setReadonly('requested_by',false);
}else{
g_form.setReadonly('requested_by',true);
}

 

 

 

make sure there is no UI Policy making it Mandatory or editable.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Community Alums
Not applicable

Yup, these are the top 2 ways I'd use - if it was me , I'd surely go with Permissions config, as it's easier to do and maintainable by SNow. 
I have a massive catalog performance issues exactly due to large catalog scripts, which were growing over the years and now it's total pain to rework the cat items... I was thinking this can happen only on purpose, but there are items giving timeout or best taking like 30+ seconds to render - rootcause => too many catalog client scripts where more than a half could be avoided using OOB functionality. 
Just sharing my recent experience, not saying one should not use those. 🙂
Cheers,
Joro

Community Alums
Not applicable

If this is for catalog variables (I got it this way) - you can open the catalog variable definition in question (requested_for) and use Permissions functionality :

JoroKlifov1_0-1705584970489.png