- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 09:10 PM
Hi Community,
How do I auto populate address based on the location field selection?
I have custom fields on hardware asset tables like; country,state,city,area and street all read-only and all referencing to cmn_location table. On Location I have set tree_picker=true. I'm in the process of auto populate respective values based on the location.
I guess it can be achieve from script include . Any code would be helpful.
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 05:09 AM
Try below code,
var GetLocationDetails = Class.create();
GetLocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
locDet: function(){
var arr = {};
gs.addInfoMessage('looping 1');
var loc = this.getParameter("sysparm_loc_det");
var gr = new GlideRecord("cmn_location");
gr.addQuery("sys_id",loc);
gr .query();
if(gr.next()){
var obj={
"street" : gr.name.toString(),
"city" : gr.parent.toString(),
"state" : gr.parent.parent.toString(),
"country" :gr.parent.parent.parent.toString()
};
var data = new JSON().encode(obj);
return data;
},
type:'GetLocationDetails'
});
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var location=g_form.getReference('location');
//alert(location.parent.getDisplayName());
var ga = new GlideAjax("GetLocationDetails");
ga.addParam("sysparm_name",'locDet');
ga.addParam("sysparm_loc_det",g_form.getValue("location"));
ga.getXML(testLoc);
function testLoc(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var returneddata = JSON.parse(answer);
alert('test'+returneddata.street);
alert(returneddata.city);//sys_id will get generated
alert(returneddata.state);//sys_id will get generated
alert(returneddata.country);//sys_id will get generated
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2019 04:16 AM
Can anyone help ?
How can we call the script include in client script without DOM manipulation?
var answer = response.responseXML.documentElement.getAttribute("answer");
var returneddata = JSON.parse(answer);
alert('test'+returneddata.street);
alert(returneddata.city);//sys_id will get generated
alert(returneddata.state);//sys_id will get generated
alert(returneddata.country);//sys_id will get generated
}
}