- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 01:55 AM
Hi Community,
I’m working on a ServiceNow catalog item and want to dynamically populate one variable based on the selection in another variable.
Scenario:
I have a variable “select_the_requested_group” with choices:
ABC
DEF
GHI
JKL
MNO
I have another variable “copy_of_select_the_requested_group” that should automatically populate with a corresponding backend value when a group is selected.
For example:
select_the_requested_group copy_of_select_the_requested_group
ABC XYZ
DEF PQR
GHI LMN
JKL STU
MNO VWX
I want this to happen automatically, without the user having to type anything.
How to Achieve This?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 02:17 AM
Hi @tilekarnilesh ,
I tried your problem in my PDI it is working fine for me please check below solution
Create 2 select box type fields
select_the_requested_group and copy_of_select_the_requested_group
In Configuration of these fields give the same backend name of choices like below
This is for select_the_requested_group
This is for copy_of_select_the_requested_group
Create a catalog client script which run onChange of select_the_requested_group and add below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// If user changes the application value → set I Change = Yes
alert("Here");
g_form.setValue('copy_of_select_the_requested_group', newValue);
}
Note: Here if you have 50 of choices it will work fine with just one line of code, you just need to give same backend name of your choices.
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 02:02 AM
This should be simple, If you only have manageable number of values you can directly do it in On change client script on "select_the_requested_group" field/variable.
if(g_form.getValue('select_the_requested_group')=='ABC')
g_form.setVaue('copy_of_select_the_requested_group' ,'XYZ');
else if(g_form.getValue('select_the_requested_group')=='DEF')
g_form.setVaue('copy_of_select_the_requested_group' ,'PQR');
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 02:08 AM - edited 10-24-2025 02:08 AM
@RaghavSh In the future, if they plan to expand their group to 50+ how can we achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 02:16 AM - edited 10-24-2025 02:21 AM
@tilekarnilesh The writing the logic in code is not a good option, I would say change your variable type to select box and define the choices/dependency in sys_choice table.
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2025 02:17 AM
Hi @tilekarnilesh ,
I tried your problem in my PDI it is working fine for me please check below solution
Create 2 select box type fields
select_the_requested_group and copy_of_select_the_requested_group
In Configuration of these fields give the same backend name of choices like below
This is for select_the_requested_group
This is for copy_of_select_the_requested_group
Create a catalog client script which run onChange of select_the_requested_group and add below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// If user changes the application value → set I Change = Yes
alert("Here");
g_form.setValue('copy_of_select_the_requested_group', newValue);
}
Note: Here if you have 50 of choices it will work fine with just one line of code, you just need to give same backend name of your choices.
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
