When a user selects a category, automatically set a default subcategory using client scripts

Siva_Prasad
Tera Contributor

I want to make a onchange client script When a user selects a category, automatically set a default subcategory using client scripts on incident table 

1 ACCEPTED SOLUTION

Syed14
Mega Guru

For this, you have to create Onchange Client script and set field name to category.

Syed14_0-1752492390075.png

PS: At first, try every task on your own for better understanding and then if you stuck somewhere then we will definitely help you.

 

 

View solution in original post

7 REPLIES 7

Ct111
Giga Sage

You can do something like this 

 

Table: incident

Type: onChange

Field name: category

 

 

 

Script :

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

// Example: set default subcategory based on category
switch (newValue) {
case 'hardware':
g_form.setValue('subcategory', 'laptop');
break;
case 'software':
g_form.setValue('subcategory', 'email');
break;
case 'network':
g_form.setValue('subcategory', 'wifi');
break;
default:
g_form.setValue('subcategory', '');
}
}

 

 

I hope this helps.

Yes this is helpful and worked perfectly

Ankur Bawiskar
Tera Patron
Tera Patron

@Siva_Prasad 

so what did you start with and where are you stuck?

It's an easy requirement.

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have recently started development course ,in that way i got this small task so i have asked in community