- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 11:00 AM
I would like to auto populate the City and State field just by entering the zip code. Any suggestions on how to accomplish that?
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 11:53 AM
script include:
var MyFavoritesAjax = Class.create();
MyFavoritesAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFavorites : function() {
var id=this.getParameter('sysparm_zipcode');// to get parameter from client side
gs.log('callidis'+id);// it will show log message in LOGS APPLICATION
var inc=new GlideRecord('cmn_location');
inc.addQuery('zip',id);
inc.query();
if(inc.next()){
this._addFavorite("state", inc.email);
this._addFavorite("city", inc.mobile_phone);
}
},
_addFavorite : function(name, value) {
var favs = this.newItem("favorite");
favs.setAttribute("name", name);
favs.setAttribute("value", value);
},
type : "MyFavoritesAjax"
});
client script:
write a onchange script on zipcode field on the form,
//please change field names with your form fields
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading )
return;
if (newValue == '') {
g_form.setValue('u_state', '');
g_form.setValue('u_city', '');
return;
}
var ga = new GlideAjax("MyFavoritesAjax");
ga.addParam("sysparm_name", "getFavorites");
ga.addParam("sysparm_caller", g_form.getValue('u_zipcode'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var favorites = serverResponse.responseXML.getElementsByTagName("favorite");
for(var i = 0; i < favorites.length; i++) {
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
if(name=='state'){
g_form.setValue('u_state',value);
}
if(name=='city'){
g_form.setValue('u_city',value);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 11:53 AM
script include:
var MyFavoritesAjax = Class.create();
MyFavoritesAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFavorites : function() {
var id=this.getParameter('sysparm_zipcode');// to get parameter from client side
gs.log('callidis'+id);// it will show log message in LOGS APPLICATION
var inc=new GlideRecord('cmn_location');
inc.addQuery('zip',id);
inc.query();
if(inc.next()){
this._addFavorite("state", inc.email);
this._addFavorite("city", inc.mobile_phone);
}
},
_addFavorite : function(name, value) {
var favs = this.newItem("favorite");
favs.setAttribute("name", name);
favs.setAttribute("value", value);
},
type : "MyFavoritesAjax"
});
client script:
write a onchange script on zipcode field on the form,
//please change field names with your form fields
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading )
return;
if (newValue == '') {
g_form.setValue('u_state', '');
g_form.setValue('u_city', '');
return;
}
var ga = new GlideAjax("MyFavoritesAjax");
ga.addParam("sysparm_name", "getFavorites");
ga.addParam("sysparm_caller", g_form.getValue('u_zipcode'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var favorites = serverResponse.responseXML.getElementsByTagName("favorite");
for(var i = 0; i < favorites.length; i++) {
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
if(name=='state'){
g_form.setValue('u_state',value);
}
if(name=='city'){
g_form.setValue('u_city',value);
}
}
}
}