Populate caller's location on Incidents

Not applicable

Very simple client script set to onChange of the Incident Caller field. When the caller is set or changed, the incident location is updated if the caller has a location specified on their profile.

=================================

function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}

var caller = g_form.getReference('caller_id');

if (caller.location) {
g_form.setValue('location', caller.location);
}
}

5 REPLIES 5

ima
Tera Contributor

Hi,

I tried this code for populating location of caller in one of the field in my incident form, but it is giving me the sys_id of the location and not the name.

Any room for improvement here.

Thanks,

Is it a reference field ? 

If its a reference field then the code above should work fine as reference fields requires sys_id. If its not a reference field then you could populate the name of location instead.

 

function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}

var caller = g_form.getReference('caller_id');

if (caller.location) {
var grLoc = new GlideRecord('cmn_location');
grLoc.addQuery('sys_id', caller.location);
grLoc.query(function(){
if(grLoc.next())
g_form.setValue('location', grLoc.name);
});
}
}

As its OOB field over Incident form, Seems like you just need to set the display value for location table. Set display true for name on cmn_location table.

ima
Tera Contributor

Hi,

Display value is already true for name in cmn_location table but still i am getting the sys_id of the location.find_real_file.png

 

My requirement is i need the Caller’s location name to be populated in Incident Short Description.

i tried both on change client script for this but no luck:

function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}
var caller = g_form.getReference('caller_id');
if (caller.location) {
var grLoc = new GlideRecord('cmn_location');
grLoc.addQuery('sys_id', caller.location);
grLoc.query(function(){
if(grLoc.next())
g_form.setValue('short_description', grLoc.name);
});
}
}

 

and

 

function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}
var caller = g_form.getReference('caller_id');
if (caller.location) {

 g_form.setValue('short_description',caller.location + ':');
}

}