Hide Category fields from a group on Incident form

jbasa
Tera Contributor

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');
}

 

 

 

 

4 REPLIES 4

Hayo Lubbers
Kilo Sage

Hi,

 

You need to use the value from the database, not the label you see. Check the choice list values:

HayoLubbers_0-1673617388747.png

 

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.

 

jaheerhattiwale
Mega Sage
Mega Sage

@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:

jaheerhattiwale_0-1673617695940.png

 

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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@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.

@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.

 

jbasa_0-1673963319246.png

 

 

Client Script

 

jbasa_1-1673963331005.png