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

Yes, I want department of the User.


Thanks


Harsh Vardhan
Giga Patron

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


var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function


}


function doAlert(caller) { //reference is passed into callback as first arguments



alert(caller.department);


g_form.setValue('description',caller.department); // just for the sake of testing i had set it on description field.


}


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

The getReference() function falls short for your use case since you need to "dot-walk" twice to get the name of the department = 1. user, 2 department.   Please see my getReferenceAdvanced solution as this will solve your issue easily.   Details can be found below and the code is on Share.


getReferenceAdvanced, g_form.getReference and GlideAjax Alternatives


sangareddy
ServiceNow Employee
ServiceNow Employee

You can use dot walking for the same.



caller_id.deparment.name



it will   get the exact value



thanks


trinadh


home
Kilo Contributor

Hi,


Alert is coming as 'undefined'.



Thanks.