Get the current user's manager and Current user's group manager in the filters.

Santhosh40
Giga Expert

Hi Experts, I need to get the records based on the following conditions/filters:

I want a filter option called “Assigned Manager” that shows Incidents where the User Reference entered is:

1. The Manager of a User in the Assigned_to field,

or

2. is the Manager of the Assignment group to which it was assigned.

---------> I had tried to the with following filters as

"Assigned_to.manager - is - gs.getUserID()"

or

"Assignment_group.manager - is - gs.getUserID()". - > but it get the records which are assigned to the current user.

Can you please share your thought to achieve this requirement.

Thanks in advance for your valuable thoughts

Thanks

Santhosh.K

 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you tried using:

gs.getUser().getManagerID();

Also have a look at:
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you tried using:

gs.getUser().getManagerID();

Also have a look at:
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thank you Mark, for your time

I tried in:

For Assigned_to.manager - is - 

javascript:gs.getUser().getManagerName();

javascript:gs.getUser().getManagerID();

But no luck.

Do we have any other way/methods to get the required users.

Again Thanks..

 

Thanks

Santhosh.K

 

Rahul Kumar17
Tera Guru

Hi

i m checking purpose only so i wrote backgroud script so u can write before query business rule

var gr=new GlideRecord('incident');
gr.query();
while(gr.next())
{
gs.print(gr.assigned_to.manager.name+ " " +gr.assignment_group.manager.name);
}

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

asifnoor
Kilo Patron

Hi Santhosh,

Find below the code which fetches the active incidents when the given user is either a manager of the assigned_to field or group manager of the assignment group.

var referenceUser = 'a8f98bb0eb32010045e1a5115206fe3a';//replace this line with your user sys_id that you get. for now i have used static id here

//Now fetch the groups of this user where he is a manager of those groups. 
var gr = new GlideRecord("sys_user_group");
gr.addQuery("manager",referenceUser);
gr.query();
var groups=[];
while(gr.next()) {
  groups.push(gr.getValue("sys_id"));
}
gs.print("Group ids where he is manager is "+groups);

var gr=new GlideRecord("incident");
gr.addActiveQuery();
var q1 = gr.addQuery("assigned_to.manager",referenceUser);
q1.addOrCondition("assignment_group","IN",groups);
gr.query();
while(gr.next()) {
gs.print("Incidents are "+gr.getValue("number"));
//write your logic here
}

 

Mark the comment as a correct answer and also helpful once worked.