Populate one field based on other field value selection

hifza chhipa
Tera Contributor

Hi ,

use case:-

1-i have two fields name Department and teams.

2-Now i want to populate department automatically on based of team selection.

for eg :-if i select team as football, basketball or throwball,   department should be automatically populated as sports.(note:for many teams there is just one department)

 

 

5 REPLIES 5

jaheerhattiwale
Mega Sage
Mega Sage

@hifza chhipa Create a on change client script on Teams field

 

Add below code

 

if(newValue == 'football' || newValue == 'basketball' || newValue == 'throwball' ){

g_form.setValue('DEPARTMENT FIELD NAME HERE', 'VALUE HERE');

}

 

Value will be sys id of department table if its a reference field

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

HI @jaheerhattiwale 

In teams table there is around 50 records and from it there are many teams which belongs to particular department.

So i believe first line of code is not feasible.

thanks

PREVIEW
 
 
 

@hifza chhipa then try this

 

var arrayOfSportsTeams = []; //Add the values in array

 

if(arrayOfSportsTeams.indexOf(newValue) >= 0){

g_form.setValue('DEPARTMENT FIELD NAME HERE', 'VALUE HERE');

}

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Community Alums
Not applicable

Hi @hifza chhipa ,

You need to populate one field based on other field in service catalog, so you can use the catalog client script and glideajax

 

  • If you want to auto populate the value in another field on same form, you can use catalog client script.

var myVar = g_form.getValue('field-name1');

and set in another field using

g_form.setValue('field-name2',myVar );

 

  • If your business need to fetch value form the table you can use the callback function or use GlideAjax.

Refer this thread for GlideAjax example auto populate values based on another field value

https://www.servicenow.com/community/itsm-forum/how-to-populate-multiple-choices-based-on-other-fiel...