Query on Client Script

vodnalar26
Tera Contributor

Hello Everyone,

I am facing an issue related to impersonation and field behavior in ServiceNow.

I wrote a Client Script where, if a specific user is impersonated, the Assignment Group field should become read-only; otherwise, it should remain editable.

The logic is working correctly for other fields, and even the setMandatory() functionality works as expected. However, setReadOnly() is not working specifically for the Assignment Group field.

I verified that:

  • The script is executing properly

  • The impersonated user is being identified correctly using g_user.userID

  • The same logic works on fields like short_description and category

But for assignment_group, the field still remains editable.

Could anyone please help me understand:

  • Is there any restriction specific to the assignment_group field?

  • Could a UI Policy, ACL, or dictionary configuration be overriding the Client Script behavior?

  • What would be the best approach to make assignment_group read-only during impersonation?

  • here I have uploaded my code

Any guidance would be greatly appreciated.

Thank you.

6 REPLIES 6

palanikumar
Giga Sage

Hi @vodnalar26 ,

 

A field can be set readonly only if it is not mandatory.

If this field is mandatory then call g_form.setMandatory('assignment_group',false) before setting readonly.

 

Thank you,
Palani

Ok, I just checked it. The script was initially working with the setMandatory() method. Later, I changed the script method from setMandatory() to setReadOnly(), and after that, the issue started occurring specifically for the Assignment Group field.

@vodnalar26 

please share your script and script config screenshots

Also share the outcome what you are getting

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

Your script should be like below (both statement should be present):

 

g_form.setMandatory('assignment_group',false);

g_form.setReadOnly('assignment_group',true);

Thank you,
Palani