The CreatorCon Call for Content is officially open! Get started here.

How do I auto populate address based on the location field selection?

Sana10
Kilo Contributor

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.

find_real_file.png

Thanks.

1 ACCEPTED SOLUTION

Shweta KHAJAPUR
Tera Guru

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
 
 }
}

View solution in original post

10 REPLIES 10

keerthi19
Tera Guru

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
 
 }
}