Get manager for requested for field

Pat Surtan
Tera Expert

Hi,

 

I want to show/get the manager for the requested for field within the Now platform side. The manager field name is u_manager. I am using this client script but it is not working.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
       var usr = g_form.getReference('requested_for',callBack);
}
function callBack(usr){
        g_form.setValue('manager',usr.manager);
}

 

Please help. Thanks in advance.

1 ACCEPTED SOLUTION

No the manager field should stay as a reference to the sys_user table. But I see the mistake. In your client script line 8 

ga.addParam("sysparm_name", "getManager");

This sysparm_name parameter ALWAYS needs to be the same value as your function name in the script include which in this case for you is called "getManagerAjax". So update that line to this

ga.addParam("sysparm_name", "getManagerAjax");

Additionally line 9 you can update to be

ga.addParam("sysparm_requestedFor", newValue);

And thats all.

This is how a Ajax structure generally looks like

var ga = new GlideAjax("Script Include Name goes here");
ga.addParam("sysparm_name", "name of the function you want to call from the above include goes here");
ga.addParam("sysparm_whateverVariableNameYouWantToSendAsParameter", "then the value you want to send in the left defined variable");
ga.getXMLAnswer(function(answer){
//logic you want to do with the answer your script include function returns
});

Hopefully this will help you in the future 🙂

View solution in original post

11 REPLIES 11

No the manager field should stay as a reference to the sys_user table. But I see the mistake. In your client script line 8 

ga.addParam("sysparm_name", "getManager");

This sysparm_name parameter ALWAYS needs to be the same value as your function name in the script include which in this case for you is called "getManagerAjax". So update that line to this

ga.addParam("sysparm_name", "getManagerAjax");

Additionally line 9 you can update to be

ga.addParam("sysparm_requestedFor", newValue);

And thats all.

This is how a Ajax structure generally looks like

var ga = new GlideAjax("Script Include Name goes here");
ga.addParam("sysparm_name", "name of the function you want to call from the above include goes here");
ga.addParam("sysparm_whateverVariableNameYouWantToSendAsParameter", "then the value you want to send in the left defined variable");
ga.getXMLAnswer(function(answer){
//logic you want to do with the answer your script include function returns
});

Hopefully this will help you in the future 🙂

Pat Surtan
Tera Expert

Hi Harun,

 

Your script worked. Thank you for your help!

 

Wondering can you help me with this one? https://community.servicenow.com/community?id=community_question&sys_id=c8caacdadbd9d590dd886c8e13961954&view_source=searchResult&anchor=answer_00de285edb91199055b5e14c139619b9&feedbacktype=answerEditor0