Variables Dependency

Burhan Shah
Tera Contributor

Hello Community,

 

How can I link RITM variables with each other?

 

For example, I have a country variable of UK. It must show the cities of UK only in city variables once the user

Selects UK variable.

 

The variables type are select box.

 

Regards,

Burhan Shah

1 ACCEPTED SOLUTION

Hello @Burhan Shah 

Since there are multiple cities it always good to add an option through script.

  • Write an onchange client script with field set to country.

OnChange catalog client script:

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

     // Clear the City field
    g_form.clearOptions('city');

    // Define a mapping of countries (in lowercase) to their respective cities
    var countryCityMapping = {
        "turkey": [
            { value: "ankara", label: "Ankara" },
            { value: "istanbul", label: "Istanbul" },
            { value: "izmir", label: "Izmir" }
        ],
        "usa": [
            { value: "new_york", label: "New York" },
            { value: "los_angeles", label: "Los Angeles" },
            { value: "chicago", label: "Chicago" },
            { value: "houston", label: "Houston" },
            { value: "phoenix", label: "Phoenix" }
        ],
        "uk": [
            { value: "london", label: "London" },
            { value: "manchester", label: "Manchester" },
            { value: "birmingham", label: "Birmingham" },
            { value: "glasgow", label: "Glasgow" },
            { value: "leeds", label: "Leeds" }
        ]
        // Add more countries and cities as needed
    };

    // Get the selected country
    var selectedCountry = newValue;
    g_form.addInfoMessage(selectedCountry);
    // Add the cities corresponding to the selected country
    if (countryCityMapping[selectedCountry]) {
        var cities = countryCityMapping[selectedCountry];
        g_form.addOption('city', '', '--Select a City--'); // Add a placeholder option
        cities.forEach(function(city) {
            g_form.addOption('city', city.value, city.label);
        });
    } else {
        g_form.addOption('city', '', '--No Cities Available--');
    } 
}

Here I have mapped for three country only, you can map for as many you want.

This script will add an option based on the country selected from the data in our script.

Note: You can set inactive false for all the city and try to populate the data from script.

This is tested in my PDI.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

7 REPLIES 7

Juhi Poddar
Kilo Patron

Hello @Burhan Shah 

Variables in RITM are the catalog variables. You will need to write onchange client script for this. Do you want this modification in catalog form or only in RITM?

 

Thank You 

Juhi Poddar 

Hi Juhi,

 

Users will submit requests through the service portal, and we need these changes applied there.

Ankur Bawiskar
Tera Patron
Tera Patron

@Burhan Shah 

what type of variables are those?

Please share some screenshots.

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

They are RITM variables (Select Box) Questions.

 

BurhanShah_0-1735115158866.png

 

BurhanShah_1-1735115196792.png