How to Test a Client Script That Disables Category Field for Non-ITIL Users on Incident Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 07:56 AM
Hi everyone! 👋
I'm working on a client-side requirement for the Incident form, where the Category field should be disabled if the currently logged-in user does not have the itil role. To implement this, I used a Script Include + Client Script with GlideAjax.
Script Include
var usercheckdata = Class.create();
usercheckdata.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userrole: function () {
return gs.hasRole('itil') ? 'true' : 'false';
},
type: 'checkUserRole'
});
Client Script (Type: onLoad)
var usercheckdata = Class.create();
usercheckdata.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userrole: function () {
return gs.hasRole('itil') ? 'true' : 'false';
},
type: 'checkUserRole'
});
How I Tested:
Impersonated a user with the itil role → Category was editable
Impersonated a user without the itil role → Category was disabled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 09:20 AM - edited 07-13-2025 09:22 AM
Hi @vaishali231 ,
1. Script Include
Make sure this is set to Client Callable = true.
var checkUserRole = Class.create();
checkUserRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userHasITILRole: function () {
return gs.hasRole('itil') ? 'true' : 'false';
},
type: 'checkUserRole'
});
2. Client Script (Type: onLoad)
var ga = new GlideAjax('checkUserRole');
ga.addParam('sysparm_name', 'userHasITILRole');
ga.getXMLAnswer(function(response) {
if (response === 'false') {
gForm.setDisabled('category', true);
}
});
})
✅How to Test
Impersonate a user with itil role → Category should remain editable.
Impersonate a user without itil role → Category should become disabled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 02:07 PM
"How to Test a Client Script That Disables Category Field for Non-ITIL Users on Incident Form"
How to test:
- is it itil_admin, admin, .... ???
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 02:24 PM
@vaishali231
if you are testing visibility on incident for itil - then itil is the "lowest" that shall be able to access an incident.
So if your conditions are based on have itil or not, all the non-itil roles that can access incident will be "higher" than itil and usually it inherits itil.
The condition shall be a little bit different unless this is a customised scenarion in your organisation.
Can you please review and let me know?
PS: when it comes to roles - be aware of (1) hasRole('itil') and (2) hasRoleExactly('itil').
(1) admin will return true, because itil is under admin
(2) user must have explicitly assigned itil, admin will return false
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 04:54 PM
But just to point out: in your message, you accidentally pasted the Script Include code twice and repeated it in the Client Script section.
In the Client Script, you don’t need to redefine the Script Include — instead, you call it from the client side using GlideAjax.
Here’s what your Client Script should look like (type: onLoad)
function onLoad() {
var ga = new GlideAjax('usercheckdata');
ga.addParam('sysparm_name', 'userrole');
ga.getXMLAnswer(function(response) {
var hasRole = response;
if (hasRole !== 'true') {
g_form.setDisabled('category', true);
}
});
}
here is how you can test this
a) Open the Incident form as your normal admin user → the Category field should stay editable.
b) Use Impersonate:
Impersonate a user who has the itil role → open the Incident form → Category should still be editable.
Impersonate a user without the itil role → open the Incident form → Category field should now be disabled (greyed out).