How to autopopulate manager field with catalog onLoad() client script.

priyanka0709
Tera Contributor
 
3 REPLIES 3

Carlos Loza
Tera Expert

Hello,

 

have you taken a look at the getReference() method on g_form:

https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideFormAPI#r_GlideForm-GetRe...

 

although not super fast performance-wise, it is the easiest way to implement what you need

Danish Bhairag2
Tera Sage
Tera Sage

Hi @priyanka0709 ,

 

No need to create an on load script for this. If we need to populate with logged in users manager you can just navigate to that variable, under default tab just paste the below code.

 

javascript: gs.getUser().getManager().getDisplayName();

 

Note: While pasting the above code remove &colon

 

But if it's like based upon some other field value input where user can be changed on the form & their manager needs to appear then u need to go via on load script do a GlideAjax call to call a script include,query the manager name in script include , return the same in script n set it.

 

Mark my answer helpful & accepted if it helps you resolve your issue.

 

Thanks,

Danish

Tai Vu
Kilo Patron
Kilo Patron

Hi @priyanka0709 

Try this trick without single line of code.

  1. Define your user variable. Sample below as "Requested for"
  2. Create the Manager variable (assume this is Reference variable type)
  3. At the section "Auto-populate", set the dependent to Requested for and the dot walk path is Manager.

TaiVu_0-1697007851589.png

 

Let me know if it works for you!

 

Cheers,

Tai Vu