display manager name

nithin19
Kilo Contributor

i have created a service catalog and on that there is a feild "manager" and "requested for", if we select a particular user in requested for feild , that users manager name should display on the manager's feild. please help me with script.  

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

you can use onChnge() catalog client script on requester field. 

either you can try with call back function or glide ajax. 

manager variable is reference type variable. ? if yes try with below code. 

 

function onChange(control, oldValue, newValue, isLoading)


{

  if (newValue == '') {

    return;

  }


  var requester = g_form.getReference('requester', setManager);


      }

function setManager(requester) {

    if (requester)


            g_form.setValue('requester_manager', requester.manager);


}

 

if manager is single line text variable the use glide ajax. 

 

Sample code for ajax. 

https://community.servicenow.com/community?id=community_question&sys_id=6caf549f1b2bbb84d01143f6fe4b...

 

If my answer helped you, kindly mark it as correct and helpful.

 

 

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

you can use onChnge() catalog client script on requester field. 

either you can try with call back function or glide ajax. 

manager variable is reference type variable. ? if yes try with below code. 

 

function onChange(control, oldValue, newValue, isLoading)


{

  if (newValue == '') {

    return;

  }


  var requester = g_form.getReference('requester', setManager);


      }

function setManager(requester) {

    if (requester)


            g_form.setValue('requester_manager', requester.manager);


}

 

if manager is single line text variable the use glide ajax. 

 

Sample code for ajax. 

https://community.servicenow.com/community?id=community_question&sys_id=6caf549f1b2bbb84d01143f6fe4b...

 

If my answer helped you, kindly mark it as correct and helpful.

 

 

thnkyu sir

Dhananjay Pawar
Kilo Sage

Hi,

Write onChange client script on Requested for field and paste below code in it

 

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

return;
}


var glideMTA = new GlideAjax('global.FetchData');
glideMTA.addParam('sysparm_name','fetchData');
glideMTA.addParam('sysparm_permit',newValue);


glideMTA.getXML(callback);
function callback(response)
{
var c= response.responseXML.documentElement.getAttribute("answer");

g_form.setValue('manager',answer);//change your field name here

}

}

 

Write Script include

name - FetchData

client callable - true

 

var FetchData = Class.create();
FetchData.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


fetchData: function() {

var permitTicket = this.getParameter('sysparm_permit');

var glidePermit = new GlideRecord('sys_user');
glidePermit.addQuery('sys_id',permitTicket);
glidePermit.query();
while(glidePermit.next())
{

return glidePermit.manager.name;
}

},

type: 'FetchData'
});

 

Thanks,

Dhananjay.