Hide Category fields from a group on Incident form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 05:38 AM
Reviewing this, I came up with the following onLoad Client script; however, it does not work for me. Any ideas?
Want to hide or remove from a group when in the Incident form some categories they will not use.
Looking at your example, I switched it to the following on the onLoad Client Script.
Do you know if this is valid?
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.removeOption('category', 'Applications');
g_form.removeOption('category', 'Hardware');
g_form.removeOption('category', 'Inquiry');
g_form.removeOption('category', 'Property');
g_form.removeOption('category', 'Network');
g_form.removeOption('category', 'Security');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 05:46 AM
Hi,
You need to use the value from the database, not the label you see. Check the choice list values:
If you need to re-add options due to a change of another field, use the addOption function. Make sure you use also there the value and the label as 3rd variable.
removeOption : https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/c_GlideFormAPI#r_GlideFormRemov...
addOption : https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/c_GlideFormAPI#r_GlideformAddOp...
Regards,
Hayo
Please mark as correct answer if this solves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 05:49 AM
@jbasa You can create the onload client script and use the GlideAjax in it as below
Client script:
function onLoad() {
var ga = new GlideAjax('AjaxUtil');
ga.addParam('sysparm_name', 'isMemberOf');
ga.getXML(processResponse);
}
function processResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
//add all remove option code here like below
g_form.removeOption('category', '<CHOICE VALUE>');
}else{
//Add all the add option code here like below
g_form.addOption('category', '<CHOICE VALUE>', '<CHOICE LABEL>' );
}
}
Script include:
Code:
var AjaxUtil = Class.create();
AjaxUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isMemberOf: function(){
return gs.getUser().isMemberOf("<GROUP NAME HERE>");
},
type: 'AjaxUtil'
});
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 06:17 AM
@jaheerhattiwale It works too well. After adding the group the ITIL user is a member of, it did hide the Categories I needed. However, it hid them from me, even though I was not in that group.
This is great; making progress and appreciate the fast replies.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2023 05:49 AM
@jaheerhattiwale Here are my modifications. It works in my DEV instance but not in prod. The group name in Prod is a little different but that name is the only change between DEV and Prod I made
Script include.
Client Script