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

Harsh Vardhan
Giga Patron

Hi Rahul,



you can use call back function by using getReference().



var caller = g_form.getReference('caller_id', showcallerTitle);


function showcallerTitle(caller) {


alert(caller.department); //if you want to set then use g_form.setValue() function.


}


My Department Field is also a reference field inside caller field.


So I am getting sys_id instead of department Name.


test1.PNG


and my caller field look alike this :


test2.PNG


so department name is itself a ref. field.


So I just want a sales should get pop up in caller department.


Thanks.


Share your script here




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Hi Rajesh,


I am pasting my scripts below.
as i have tried both scripts but they are giving me same output i.e. SYS_ID.





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



//Script 1:


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


var gr = new GlideRecord('sys_user');


gr.addQuery('sys_id', caller);


gr.query();


if(gr.next())


{


alert(gr.department);


}



  // Script 2:



//var caller = g_form.getReference('caller_id', getDepartmentName);


//function getDepartmentName(caller) {


//alert(caller.department);


//}



Thanks.