We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

Ankur Bawiskar
Tera Patron

@vodnalar26 

if that field is mandatory then you can't make it readonly

As per approach shared by @palanikumar make it non-mandatory and then readonly

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

Tanushree Maiti
Tera Patron

Hi @vodnalar26 

 

A field cannot be both mandatory and read-only at the same time.

As a workaround, you can initially keep the field mandatory. Once the user enters a value, create a UI Policy that checks whether the field is not empty, and then use a UI Policy Action to make the field read-only.

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti