Populated the location based on country

Shaik Najma
Tera Contributor

I have two variables 1. Impacted Country 2. Impacted Location and both are reference variables to cmn_location table 
Requirement is if user picks country based on country locations should shown to users to select, until user selects the country locations should not return any records .if user remove the selected location country should also removed and refreshed and vice versa.

Can anyone help me with this requirement.

4 REPLIES 4

Chaitanya ILCR
Mega Patron

Hi @Shaik Najma ,

you can add a reference qualifier on the impacted location variable

ChaitanyaILCR_0-1769680207007.png

 

and create a onChange client script on the impacted country variable

 

 

ChaitanyaILCR_1-1769680335656.png

 

Note: replace the impacted_country and impacted_location with actual names of your variable

 

still having issue

please share the variable screenshots along with their type specifications information

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

Ankur Bawiskar
Tera Patron

@Shaik Najma 

what's the point in 2 variables both pointing to same cmn_location table?

Example: If I select Australia it's a location only but just that it has different states and each of those are different locations

AnkurBawiskar_0-1769680913112.png

I believe you should 1st discuss with customer what they actually want

šŸ’” 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

adityahubli
Tera Guru

Hello @Shaik Najma ,

 

I tried your use case , for that i have created following script include 

var PopulateLocation = Class.create();
PopulateLocation.prototype = {
    initialize: function() {},

    getLoc: function(id) {
        var arr = [];
        var country;
        var ga = new GlideRecord('cmn_location')
        if (ga.get(id)) {
            country = ga.country.toString();
        }

        var gr = new GlideRecord("cmn_location");
        gr.addQuery('country', country);
        gr.query();
        while (gr.next()) {
            arr.push(gr.sys_id.toString());

        }
        var data = arr.join(',')
        return 'sys_idIN' + data;
    },

    type: 'PopulateLocation'
};

Screenshot (5).png

Above script include is called in Location field reference qualifier 

type:advanced 

Reference qualifier :javascript:new PopulateLocation().getLoc(current.variables.country);

 

Screenshot (6).pngScreenshot (7).png

 

To see country in country variable :

Screenshot (8).png

 

 

 

 

Screenshot (9).png

Screenshot (11).png

Screenshot (11).png

 

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya