Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get department Name from caller field on incident Form

home
Kilo Contributor

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.

20 REPLIES 20

function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if (isLoading || newValue === '') {


return;


}


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

var gr= new GlideRecord('sys_user');
gr.addQuery('sys_id',caller);
gr.query();
if(gr.next()){

    var gar1=new GlideRecord('cmn_department');
    gar1.addQuery('sys_id',gr.department);

    gar1.query();
    if(gar1.next()){
var dept_name = gar1.name;
g_form.addInfoMessage('Department :' +dept_name);

    }

    }

    
}