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

Mihir Mohanta
Kilo Sage

In the incident form make the Department field reference type referenced to cmn_department table.



Then try the script provided by Harsh.


Hi Mihir,



This Way?




var dept= g_form.getReference('cmn_department ', showcallerTitle);


function showcallerTitle(dept) {


alert(dept.department);


}




Thanks.


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.


}


Harsh Vardhan
Giga Patron

Harsh Vardhan
Giga Patron

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



}