Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Automatically Populate a Catalog Item Variable Based on Another Variable Selection

tilekarnilesh
Giga Guru

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?

1 ACCEPTED SOLUTION

Sarthak Kashyap
Mega Sage

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

SarthakKashyap_0-1761297148958.png

In Configuration of these fields give the same backend name of choices like below 

This is for select_the_requested_group

SarthakKashyap_1-1761297196732.png

This is for copy_of_select_the_requested_group

SarthakKashyap_2-1761297248629.png

 

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);

}

SarthakKashyap_3-1761297295603.png

 

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 

SarthakKashyap_4-1761297334028.png

SarthakKashyap_5-1761297354344.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

 

 

 

View solution in original post

8 REPLIES 8

Working fine Thanks..

Ankur Bawiskar
Tera Patron
Tera Patron

@tilekarnilesh 

what do you mean by backend value?

are you saying you want choice value to be auto-populated in 2nd variable?

If yes then what's the business requirement for this 2nd variable when user is already selecting the choice in 1st variable?

It's just a repetition of the info

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar User choice values and backend groups are different. The backend developer team has separate values that users may not understand. Linking these will make it easier for users to select correctly, while the backend team can continue working according to their group values..

@tilekarnilesh 

the Answer you marked correct is doing what I mentioned

I still don't think it's a valid business requirement to simply get the choice value from 1st variable and populate in 2nd.

Could you give me the exact business use-case here?

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