Client Script to Auto-Populate Field on Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 02:42 PM
Stuck with an onChange client script that uses synchronous GlideAjax to auto-populate the field 'desk location' on behalf of.
Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('x_g_irm_dos_inc.DeskLocationUtils');
ga.addParam('sysparm_name', 'getLocation');
ga.addParam('sysparm_desk', g_form.getValue('sys_user'));
ga.getXML(autoPopulate);
function autoPopulate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != '' && answer != g_form.getValue('desk location')) {
g_form.setValue('desk location', answer);
}
}
}
Script Include
DeskLocationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDesk: function() {
var dsk = this.getParameter('sysparm_desk');
var gr = new GlideRecord('sys_user');
gr.addQuery('u_desk_location', dsk);
gr.query();
if (gr.next()) {
var desk = gr.sys_id;
}
return desk;
},
getLocation: function() {
var loc;
var dsk = this.getParameter('sysparm_desk');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', dsk);
gr.query();
if (gr.next()) {
u_desk_location = gr.u_desk_location;
}
return loc;
},
type: 'DeskLocationUtils'
});
Desk location is a string field on the Incident table named x_g_irm_dos_inc_desk_location, while the desk location field name on the user table is u_desk_location. Any help with the above script(s) is greatly appreciated!
Thank you!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 03:13 PM
Hi in your client script g_form.getValue('sys_user')) // in place of sys user put field name from incident table. For example x_g_irm_dos_inc_desk_location or newValue
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 06:43 PM
ga.addParam('sysparm_desk', g_form.getValue('sys_user')); // this will not work in your script because there is no field called sys_user on incident form.
What is the field on incident form to get User sysid? is that called_id field?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 06:46 AM
Thank you for the reply! The field that should trigger the auto-populate is 'on behalf of' x_g_irm_dos_inc_on_behalf_of. The caller_id field in this case does not auto-populate, since the person submitting the request is different than the person submitting it for. Thus, I am wondering since the on behalf of field doesn't exist on the sys_user table, how we can capture the sys_id of that user in the client script for Incident?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 09:37 PM
If you are doing it based on caller field it should be caller_id , in place of sys_user