Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

when changing category on incident form it is not changing sub category in onchange client script

ravitejak
Tera Contributor
 
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@ravitejak 

subcategory is dependent on category

When you select category subcategory will show dependent values.

what's not working as expected?

If my response helped please mark it correct and close the thread so that it benefits future readers.

View solution in original post

Rushi Savarkar
Mega Sage

Hello @ravitejak 

Hope you are doing well!

 

First thing is, you can use the Dependent Value functionality to achieve this requirement. If you are using OnChange client script and it giving error then please share here. 

Below is my sample script in which I have created Category and Subcategory fields and written the onchange client script with addOption() and removeOption() methods. You can customize the script as per your field data:

OnChange Client Script:

Type: Onchange

Field Name: Category

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
		g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.removeOption('u_subcategory', 'iTune', 'iTune');
		g_form.removeOption('u_subcategory', 'USB', 'USB');
        g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
        return;
    }
	//alert(newValue);
    if (newValue == 'Software') {

        g_form.addOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.addOption('u_subcategory', 'iTune', 'iTune');

        g_form.removeOption('u_subcategory', 'USB', 'USB');
        g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');

    } else if (newValue == 'Hardware') {
        g_form.addOption('u_subcategory', 'USB', 'USB');
        g_form.addOption('u_subcategory', 'Mouse', 'Mouse');

        g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.removeOption('u_subcategory', 'iTune', 'iTune');

    }

}

Please let me know in case you need help with this requirement 

Thank you!

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@ravitejak 

subcategory is dependent on category

When you select category subcategory will show dependent values.

what's not working as expected?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Rushi Savarkar
Mega Sage

Hello @ravitejak 

Hope you are doing well!

 

First thing is, you can use the Dependent Value functionality to achieve this requirement. If you are using OnChange client script and it giving error then please share here. 

Below is my sample script in which I have created Category and Subcategory fields and written the onchange client script with addOption() and removeOption() methods. You can customize the script as per your field data:

OnChange Client Script:

Type: Onchange

Field Name: Category

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
		g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.removeOption('u_subcategory', 'iTune', 'iTune');
		g_form.removeOption('u_subcategory', 'USB', 'USB');
        g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
        return;
    }
	//alert(newValue);
    if (newValue == 'Software') {

        g_form.addOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.addOption('u_subcategory', 'iTune', 'iTune');

        g_form.removeOption('u_subcategory', 'USB', 'USB');
        g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');

    } else if (newValue == 'Hardware') {
        g_form.addOption('u_subcategory', 'USB', 'USB');
        g_form.addOption('u_subcategory', 'Mouse', 'Mouse');

        g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
        g_form.removeOption('u_subcategory', 'iTune', 'iTune');

    }

}

Please let me know in case you need help with this requirement 

Thank you!