Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to make read only fields to certain role users using UI policy ?

String
Kilo Sage

Hi Team ,

Am trying to make read only fields in incident for agent role users ,But I can't  find  any option for roles in UI policy 

 

Please guide me 

2 ACCEPTED SOLUTIONS

Prince Arora
Tera Sage

@String 

 

This scenario is best handled with the help of ACLs instead of UI policy, but still if you want to make read only with script you can create a new client script "on load" on the incident table and try below mentioned script(Not tested):

 

 

if(g_user.hasRole("ROLE") ) {
	 var fields = g_form.getEditableFields();
         for (var x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], true);
         }
	}

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

@String 

 

I have seen you marked my answer helpful!

Please Accept the solution if it has answered your query, it would be helpful for future readers too

View solution in original post

5 REPLIES 5

Rahul Kumar17
Tera Guru

hi @String ,

 

To make a field read-only for a specific role in ServiceNow, you can use a combination of UI Policies and Access Control. Here are the steps to achieve this:

  1. Go to the form view of the Incident table.
  2. Click on the gear icon in the top-right corner and select "Configure > Form Layout".
  3. Drag and drop the field(s) you want to make read-only to the "Additional actions" section.
  4. Click on the field you want to make read-only and note the "Variable name" in the right-hand side pane.
  5. Go to "System Security > Access Control > Roles" and open the Agent role.
  6. Create a new record in the "Read" column for the Incident table.
  7. In the "Conditions" section, add the condition "Variable name" "is" "sys_read_only".
  8. Save the record.
  9. Go to "System Definition > UI Properties" and create a new UI Policy for the Incident table.
  10. Set the "UI Policy" condition to "true".
  11. Add an action to set the read-only field(s) to "true".
  12. In the "Advanced" section of the action, add the condition "Current > Role" "is" "agent".
  13. Save the UI Policy.

Now, when an Agent user views the Incident form, the specified field(s) will be read-only.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar