How to create User criteria with the script to check whether the logged-in user has any direct reportee who are active and from XYZ location can access the HR catalog

Deactivate User
Tera Contributor

How to create User criteria with the script to check whether the logged-in user has any direct reportee who are active and from XYZ location can access the HR catalog

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use this user criteria advanced script

answer = checkCondition();

function checkCondition(){
	var gr = new GlideRecord("sys_user");
	gr.addActiveQuery();
	gr.addQuery("manager", user_id);
	gr.addQuery("location.name", "XYZ"); // give location name here
	gr.query();
	return gr.hasNext();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@Pradeepa Boopat 

Can you post a new question and tag me there as this is an older thread?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mohith Devatte
Tera Sage
Tera Sage

hello @Gaurav Rathaur ,

i think you can try this so if that person has reportees he must be a manger for those reportees so you can try this 

answer=false;
isManager();
function isManager()
{
var gr = new GlideRecord('sys_user');
gr.addQuery('manager',gs.getUserID());
gr.addQuery('active',true);
gr.addQuery('location','your_cmn_location_record_sys_id');
gr.query();
if(gr.next())
{
answer=true;
}
else
{
answer=false;
}
}

Hope this helps 

Mark the answer correct if this helps you