Make Assignment read only based on the form selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 04:02 AM
Hi
Want to make the Assignment group read only when a catalog item selected and for admin it should be editable
can anyone help me with this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 04:49 AM
@DSV22 On your Assignment Group variable, in the permissions tab, simply add admin role in the write and create roles. This field will be non editable for admins.
Please mark my response helpful and accepted solution if it addresses your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 04:50 AM
Hi @DSV22 ,
You want to ensure that:
- The "Assignment group" field on a catalog item form is read-only for users who are not admins.
- The "Assignment group" field is editable for users with the admin role.
Steps to Implement:
Ensure the Assignment Group Field is Not Mandatory:
- First, make sure that the "Assignment group" field is not set as mandatory if it's not supposed to be required for everyone.
Create a Catalog Client Script:
- You need to create a Catalog Client Script that will handle the visibility and editability of the "Assignment group" field based on the user’s role.
Write the Client Script:
- Go to ServiceNow and navigate to the catalog item where you want to apply this script.
- Create a new Catalog Client Script and use the following code:
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_user.hasRole('admin'))
{
g_form.setReadOnly('assignment_group',false); //assignment_group is the Backend Value of Variable Assignment Group
alert('true');
}
else{
g_form.setReadOnly('assignment_group',true);
alert('you are not a admin');
}
}
- Explanation:
- g_user.hasRole('admin'): Checks if the current user has the admin role.
- g_form.setReadOnly('assignment_group', false): Makes the "Assignment group" field editable.
- g_form.setReadOnly('assignment_group', true): Makes the "Assignment group" field read-only.
- Alerts: Provide a visual confirmation of whether the field is editable or read-only based on the user’s role.
Test the Script:
Make sure to test the script by logging in with different user roles (admin and non-admin) to confirm that the "Assignment group" field behaves as expected.
It is Working Fine with my PDI ,
Please Accept the Solution , and Mark it as Helpful ,
Thanks Regards ,
Badrinarayan