Make Assignment group and Assigned to Read Only When Logged in User Don't Have Specified Role.

satishyelmule
Tera Contributor

Hi All,

How to Make Assignment group and Assigned to Read Only When Logged in User Don't Have admin or Incident manager Role. 

This Task can be performed by Two ways :

  • ACL field Level
  • Client Script (onload)

Via ACL is Working Fine, but when I am trying via Client Script is Not Working.

for knowledge purpose I am trying this Client Script but it is not Working.

 

Client Script Code:

function onLoad() {
    //Type appropriate comment here, and begin script below

var isAdmin= g_user.hasRole('admin');
var isIncidentManager= g_user.hasRole('incident_manager');

if(!isAdmin || !isIncidentManager){
    alert('user do not have specified Role');
    g_form.setReadOnly('assignment_group',true);
    g_form.setReadOnly('assigned_to',true);
   
}
}
 
Thanks in Advance !!!
 
 
 

 

6 REPLIES 6

Community Alums
Not applicable

HI @satishyelmule ,

please follow the tread so that you will let know what this not achievable from onload client script.

https://www.servicenow.com/community/developer-forum/onload-client-scrip-to-set-the-field-readonly-d...

 

Thanks

please mark as solution accepted and helpful.

Satishkumar B
Giga Sage
Giga Sage

@satishyelmule for your client script approach. You may need to update your condition as below. Rest of the code looks good.

if(!isAdmin && !isIncidentManager)

 

market helpful 👍and accept the solutionif this help you to understand!!

Hi @satishyelmule 

You can use the code given by @Satishkumar B 

But make sure the variable name should be 

isAdmin

 

Thanks,
Murthy

Najmuddin Mohd
Mega Sage

Hi @satishyelmule ,

Add the same code in the UI Policy script to complete this requirement with on Load checkbox true.
I have tried it and it works.


I believe there is some UI Policy that is overriding the client script.

 

NajmuddinMohd_0-1723229055423.png


Mark as helpful, if this helps you.

Regards,
Najmuddin.