Setting default value on variable to user manager name

goller
Tera Contributor

Heya!

I'm trying to set the default value of a reference variable on a catalog item. The reference variable is referencing users with a certain role in our organization, leaders/managers have this role.

I've tried gs.getUser().getManagerID() but I get no value? I can confirm that the user has a manager.

Thanks,
goller

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hi @goller 

If you are doing this in scoped application it will not work.

Instead you can use below:

 

javascript: var loggedinManager; 
var gr=new GlideRecord("sys_user");
gr.get(gs.getUserID());
loggedinManager=gr.manager.toString();
loggedinManager;

MurthyCh_0-1666271788747.png

 

 

Hope it helps

Thanks,
Murthy

View solution in original post

5 REPLIES 5

AnubhavRitolia
Mega Sage
Mega Sage

Hi @goller 

 

You need to create a Script Include 'UserManagerID' and function 'getManager()'. Please find the code of this function below:

 

getManager: function() {
var manager;
 var grUser = new GlideRecord('sys_user');
 if (grUser.get(gs.getUserID())) {
            var manager = grUser.manager;
}
return manager;
},

 

Now use below link in your Default value of Reference Variable:

 

javascript: new UserManagerID().getManager();

 

AnubhavRitolia_0-1666272107071.png

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023