Want to make a field NON-mandatory when a particular value is selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 02:51 PM
Hello -
I think this should be simple, but cannot seem to figure it out. Went a case is created the ask is for when the Maintenance Entitlement value is selected in the drop down for the Group Category field (group_category) that the field above it (also called Maintenance Entitlement) will NOT be mandatory. There is a client script created that makes that field mandatory upon selecting a group category. There are multiple values in the group category drop down and all of the REST of them, when they are selected then the Maintenance Entitlement field SHOULD be mandatory. So, it's just this one value getting selected that it should be non-mandatory. Sorry for the run around and if that is confusing..but here is the code...
function onLoad() {
//g_form.addInfoMessage(g_form.getValue('contact_type'));
if (g_form.getValue('contact_type') != 'email')
return;
var ga = new GlideAjax('USBgetGroupCategory');
ga.addParam('sysparm_name', 'getEntitlements');
ga.addParam('contact', g_form.getValue('contact'));
ga.getXMLAnswer(handleResponse);
function handleResponse(response) {
if (response) {
//g_form.addInfoMessage(response);
if (response == 'multiple') {
g_form.setMandatory('u_poc_entitlement', 'true');
return;
}
g_form.setValue('u_poc_entitlement', response);
}
}
}
u_poc_entitlement is the field value name for the Maintenance Entitlement field...thus, as you can see above, it makes it "true" for mandatory. That's fine, but I need it to skip doing that if Maintenance Entitlement is selected in the drop down of group category.
I thought I could just do group_category != 'Maintenance Entitlement'; and it would skip that and not mark it mandatory, but that does not seem to work 🙂
Any suggestions?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 03:11 PM
A screenshot of the form would help.
There's no variable "group_category " anywhere in the code. What is the type of variable "group_category"?
The script in the question is "onLoad". Field "group_category" won't be set when the form is loading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 03:20 PM
Here's the case form. I had added that line of code and then removed it because it wasn't doing anything 🙂
But also, I see this in the dictionary...it then uses sys_user_group as the choice table and then under that table it uses Group Category, but that field column name is u_group_category.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 03:40 PM
According to the information provided, it'll be necessary to do like the following because the name fo the variable is "u_group_category" and it's referencing sys_user_group table.
u_group_category.name != 'Maintenance Entitlement'