Populate caller's location on Incidents

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2009 10:40 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 12:06 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 02:06 AM
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);
});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 02:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 02:57 AM
Hi,
Display value is already true for name in cmn_location table but still i am getting the sys_id of the location.
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 + ':');
}
}