Need to grant Change Manager Role access to read only field

adrianh
Mega Guru

Greetings, 

Relative newbie here with limited ServiceNow knowledge so please be gentle.  🙂 

 

I have the following requirement: 

I would like to grant the Change Manager role access to edit a field which has been tagged via UI Policy to be read only after the state of a Change Request moves from New to Assess. 

Backgound: 

We have a field called "Technical Approval" in our Change Request form. The purpose of this selection field is to allow the Change Coordinator to select users from the User table who will act as Technical Approvers on the Change Request.

The Approvers tab gets populated with the names from this Technical Approver list once specific Change Tasks are completed in the workflow. Once those Technical Approvers have completed their Approver items, the Change Manager then gets populated in the Approvers tab to Approve the Change.

So the flow is: QA change tasks are completed, Technical Approvers get populated in the Approvers tab which are then completed and then the CM Approver item gets populated in the Approver tab to approve the Change. 

We only want the Change Coordinator to be able to edit this field when the Change is in a NEW state for audit reasons. As such there is a UI Policy which locks down the field as soon as the Change Request moves to Assess. 

Problem

At times users do not add the correct tech approvers or miss them entirely etc. The Change Manager then has to deactivate the read only UI Policy, update the technical approvers field and reactivate the UI Policy. Pain in the butt. 

Requested Solution: 

I would like for the Change Manager role to be able to override the read only UI Policy so they can edit the field without having to log in as Admin and deactivate/reactivate the policy. 

Does anyone have any thoughts on how to easily do this? I don't script, so I may be hooped here 🙂 

Thanks in advance

1 ACCEPTED SOLUTION

Abhishek77
ServiceNow Employee
ServiceNow Employee

Hi adrianh,

As what i understood you want the field t be editable for users with Change Manager role.

In the Ui Policy just write a if condition to check if the user has that role or-else make the field read only.

 

This also can be done by client script also

function onLoad() {

if(g_user.hasRole('rolename')){

g_form.setReadOnly('fieldname', false);

}

Revert back with more queries if any

Mark the answer as Correct/Helpful based on its impact.

View solution in original post

6 REPLIES 6

Hi Abhishek,

Thank you for following up on this question. Much appreciated.

I just had a chance to play around with this now.

On my first attempt it gave me an error about missing function onCondition declaration.

So I then played with the script as below and it is still not allowing the field to be editable. I am probably missing something obvious, but this is a really good learning experience 🙂

Script:

Execute if True

function onCondition(){}
function onLoad(){
 
 if(g_user.hasRole('Change_Manager'))
   
 g_from.setReadOnly('u_technical_approvers',false);
}

 

Execute if False

function onCondition(){}
function onLoad(){
 
 if(g_user.hasRole('Change_Manager'))
   
 g_from.setReadOnly('u_technical_approvers',true);
}

 

Here's how I created the UI Policy

Opened UI Policy

Select New

Table = Change Request

Short Desc = Tech Approval field for CM

When to apply Condition

State greater than New

Item is active

And the script is as above

I've also attached the script

 

Again Abhishek

Thanks for taking the time to teach

 

 

adrianh
Mega Guru

Hi Abhishek,

I played with the script and got it to work! ! ! !

 

The following script seems to give me what I need.

Execute if True:

function onCondition(){
 
 if(g_user.hasRole('Change_Manager'))
   
 g_from.setReadOnly('u_technical_approvers',false);
}

 

Execute if False:

function onCondition(){
 
 if(g_user.hasRole('Change_Manager'))
   
 g_from.setReadOnly('u_technical_approvers',true);
}

 

My condition was that State must be greater than new.

In my test if I access a record where the user is NOT in the CM group and they cannot update unless in a State of new.

If the user is in the CM Group, they are able to update the field as I was hoping for.

Thanks for your assistance