Populating phone code based on country from cmn_location table

Ankita9
Tera Contributor

Hi All,

 

I want to fetch phone field(contains code eg: +91 for India, +65 for Sweden) value which will be based on country selection both fields are present on cmn_location table.
I also have another field called country on catalog item which is a lookup selectbox referring cmn_location. 

Can someone please suggest what is wrong with the script. I'm getting empty value in gr.phone.

 

Ankita9_0-1689869078446.png

 



Onchange Client Script on country field: 

Ankita9_0-1689869277973.png

 

Script Include : 

Ankita9_1-1689869312000.png

 

Thanks in advance!!

 

1 ACCEPTED SOLUTION

Pratiksha_45
Kilo Sage

Hello @Ankita9 ,

1.) In the client Script line no. 9 you have passed the cou variable in the single parenthesis. So remove the parenthesis. - ga.addParam("sysparm_country", cou);

 

2.) In client script, line no. 13 replaced with-

var answer = response.responseXML.documentElement.getAttribute("answer");

 

3.)In the Script include after gr.query(); you haven't add code for if block.

Please refer following code for that,

 

getPhone: function() {
var ph;
var loc = this.getParameter('sysparm_country');
var gr = new GlideRecord("cmn_location");
gr.addQuery("country", loc);
gr.query();
if (gr.next()) {
ph = gr.phone;
}
return ph;
},

 

 

Please mark as helpful if my answer is helpful to you.

Thanks !

 

 

View solution in original post

1 REPLY 1

Pratiksha_45
Kilo Sage

Hello @Ankita9 ,

1.) In the client Script line no. 9 you have passed the cou variable in the single parenthesis. So remove the parenthesis. - ga.addParam("sysparm_country", cou);

 

2.) In client script, line no. 13 replaced with-

var answer = response.responseXML.documentElement.getAttribute("answer");

 

3.)In the Script include after gr.query(); you haven't add code for if block.

Please refer following code for that,

 

getPhone: function() {
var ph;
var loc = this.getParameter('sysparm_country');
var gr = new GlideRecord("cmn_location");
gr.addQuery("country", loc);
gr.query();
if (gr.next()) {
ph = gr.phone;
}
return ph;
},

 

 

Please mark as helpful if my answer is helpful to you.

Thanks !