How to get department Name from caller field on incident Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 03:55 AM
Hi Team,
So a query is, how to get department name of user on incident form from caller reference field on a text field in incident form(or alert will also do)?
As Caller is a reference field & department inside it is also a reference field, so i am finding a difficulty in getting a name of department on form through client script with glideRecord.
a sample script will be very heplful.
Thanks.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:38 PM
In the incident form make the Department field reference type referenced to cmn_department table.
Then try the script provided by Harsh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:44 PM
Hi Mihir,
This Way?
var dept= g_form.getReference('cmn_department ', showcallerTitle);
function showcallerTitle(dept) {
alert(dept.department);
}
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:55 PM
Make sure the Department field in incident table is reference type referenced to cmn_department table.
Script:
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
function doAlert(caller) { //reference is passed into callback as first arguments
g_form.setValue('description',caller.department); // just for the sake of testing i had set it on description field.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:57 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 11:14 PM
here you go.
Script Include: Make sure you checked client callable check box.
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDept :function()
{
var name='';
var id = this.getParameter('sysparm_id');
var dep=new GlideRecord('sys_user');
dep.addQuery('sys_id', id);
dep.query();
if(dep.next())
{
name=dep.department.getDisplayValue();
}
gs.log('here is:'+name);
return name;
},
type: 'test'
});
Client Script: on change on caller field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getValue('caller_id');
var graj=new GlideAjax('test');
graj.addParam('sysparm_name', 'getDept');
graj.addParam('sysparm_id', caller);
graj.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('hellow here:'+answer);
}
//Type appropriate comment here, and begin script below
}