Based on Region field country field has to be auto populate

sasi
Tera Contributor

Hi, 

 I have a scenario in catalog client script, in a catalog item i have two variables region and country.based on region field country field has to be auto populate. for example if i will select Asia pacific in region variable only Asia pacific countries has to be Auto Populate in country field.

 

Thanks.

3 REPLIES 3

Abhishek Pidwa
Kilo Guru

You can do this by Reference Qualifier on the variable. Under Type Specifications tab , you can specify something like this :

 

Prins Kumar Gup
Giga Guru

Hi,

Can you try below catalog client script and script include. I believe belive it's helpful for you.

Script Include:

var getRegionCountry= Class.create();
getLocationCity.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRegion: function() {
		var region =  this.getParameter('sysparm_u_region');
		var data = {};
		var gr = new GlideRecord(table_name);//table name
		if(gr.get(region )){
			data.country = gr.getValue('country');
			
		}
		var json = new global.JSON().encode(data);
		return json;
    },
 type: 'getRegionCountry'
}

Client Script: Onchange client script

function onChange(control, oldValue, newValue, isLoading) {
	if (newValue == '') {
		g_form.setValue("u_country",'');	
		return;
	}
	var ga = new GlideAjax('getRegionCountry'); 
	ga.addParam('sysparm_name','getRegion'); 
	ga.addParam('sysparm_u_region',newValue); 
	ga.getXML(HelloWorldParse); 
	function HelloWorldParse(response) {    
		var answer = response.responseXML.documentElement.getAttribute("answer"); 
		answer = JSON.parse(answer);
		g_form.setValue("u_country",answer.country);
	}
}

Please Hit like, Helpful or Correct depending on the impact of the response if this solves your query!!

Thanks,

PKG

asifnoor
Kilo Patron

Hi,

You can do this with the help of the script include and reference qualifiers.

Script Include

Name: getRegionCountry

ClientCallable: Checked

var getRegionCountry= Class.create();
getRegionCountry.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountry:function(region) {
		var data = [];
		var gr = new GlideRecord(table_name);//mention your table name
		gr.addQuery("region_id",region); //replace this with your region_id column name
                gr.query();
                while(gr.next()) {
                  data.push(gr.getValue("sys_id"));
                }
		return 'sys_idIN' + data;
    },
 type: 'getRegionCountry'
});

 

once this is created, now go to country field. Under Type specifications, select Reference Qualifier as Advanced and then mention this

javascript:new getRegionCountry().getCountry(current.region);

Mark the comment as a correct answer and also helpful once worked