Populate one field based on other field value selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:25 PM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:30 PM
@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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:54 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:16 PM
@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');
}
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:30 PM
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