The CreatorCon Call for Content is officially open! Get started here.

Want to make a field NON-mandatory when a particular value is selected

allentschumper1
Tera Contributor

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?

3 REPLIES 3

Hitoshi Ozawa
Giga Sage
Giga Sage

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. 

 

 

allentschumper1
Tera Contributor

Here's the case form.  I had added that line of code and then removed it because it wasn't doing anything 🙂

find_real_file.png

 

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.  

find_real_file.png

 

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'