hide subcategory dropdown that is dependent on channel and category.

Deepanshi1
Mega Guru

hi i have one case form. when i select integration as channel and account payable as category i need to hide one option from subcategory dropdown. how can i do it?

1 ACCEPTED SOLUTION

Can you confirm that "account_payable" is the actual value of that category and that "integration" is the actual value of that channel name?

View solution in original post

9 REPLIES 9

Anirudh Pathak
Mega Sage

Hi,

You can try an on change client script -

var channel = g_form.getValue('your field name');
var category = g_form.getValue('your field name');

if(channel == 'integration' && category == 'account payable') {
       g_form.removeOption('subcategory', 'subcategory value');
}

 

on which field shall i put validation on my client script ? chanel or category?

Amit Pandey
Kilo Sage

Hi @Deepanshi1 

 

You can write an onChange Client Script, set the field name to subcategory and use the following code-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var channel = g_form.getValue('channel'); // Assuming 'channel' is the name of the Channel field
    var category = g_form.getValue('category'); 
    var subcategoryField = g_form.getControl('subcategory'); 

    if (channel === 'Integration' && category === 'Account Payable') {
        subcategoryField.removeOption('option_to_hide'); // Replace 'option_to_hide' with the value of the option you want to hide
    }
}

Please mark my answer helpful and correct.

 

Regards,

Amit

bradleydebono
Mega Guru

Good day,

 

The answer to this query will depend a little bit on your setup. But the general principles will be the same. 

 

In general, you will want to use at least 1 Client Script. This Client Script will run on the Case table and have a type of "onChange" and point to your "Channel" field.

 

The code for your client script will look like this...

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if (newValue == "integration" && g_form.getValue("category") == "account_payable") {
		g_form.removeOption('subcategory','option_to_remove');
	} else {
		g_form.addOption('subcategory','option_value', 'option_label');
	}
}

 

This will now hide the "option_to_remove" option from your "Subcategory" field when the "Channel" field is changed to "Integration". 

However, depending on your setup, it may be possible for users change the "Subcategory" field after they have submitted the form. So you may want to create a Client Script that runs onLoad with the following code...

function onLoad() {
   
   if (g_form.getValue("contact_type") == "phone" && g_form.getValue("category") == "inquiry") {
		g_form.removeOption('subcategory','option_to_remove');
   }
   
}

 

Please note I am using "contact_type" above because this is the value of the "Channel" field on my PDI. You may want to double check this in your instance. 

If this helped solve your query. Please mark it as the solution. It really helps me out. If it was in any way useful, please mark it as useful!