User criteria to check if user is Manager AND he belongs to specific Location

KSLN SAHITHI
Tera Expert

Hi all, I have a condition where if a user belongs to Location: Wroclaw and if he "Is Manager", then only the record producer is visible, I tried writing the script and added Wroclaw iin locations and checked "Match all". But it is not working. Any idea on how to do this?

10 REPLIES 10

Will this work for "Is Manager"? as it is a check box. It still restricts user from viewing.

answer = checkCondition();
function checkCondition(){
	var gr = new GlideRecord("sys_user");
	gr.addQuery('u_ismanager', true);    // modified here, it worked
	gr.addQuery();
	gr.setLimit(1);
	gr.query();

	var rec = new GlideRecord('sys_user');
	rec.get(user_id);
	var locationName = rec.location.name;

	if(gr.hasNext() && locationName.indexOf('Wroclaw') > -1)
		return true;
	else
		return false;

}

Hi @KSLN SAHITHI 

update as this since you want to check if logged in user has u_manager checkbox true or not

answer = checkCondition();

function checkCondition(){
	var gr = new GlideRecord("sys_user");
	gr.addQuery("sys_id", user_id);
	gr.addQuery('u_ismanager', true);    // modified here, it worked
	gr.query();

	var rec = new GlideRecord('sys_user');
	rec.get(user_id);
	var locationName = rec.location.name;

	if(gr.hasNext() && locationName.indexOf('Wroclaw') > -1)
		return true;
	else
		return false;

}

Regards
Ankur

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

answer = checkCondition(); function checkCondition(){ var gr = new GlideRecord("sys_user"); gr.addQuery('u_ismanager', true); //modified, this worked gr.addQuery(); gr.setLimit(1); gr.query(); var rec = new GlideRecord('sys_user'); rec.get(user_id); var locationName = rec.location.name; if(gr.hasNext() && locationName.indexOf('Wroclaw') > -1) return true; else return false; }

Mahendra RC
Mega Sage

Hi,

Could you please check with below script:

answer = checkCondition();
function checkCondition(){
	var gr = new GlideRecord("sys_user");
	gr.addQuery("u_ismanager=true^locationLIKEWroclaw");    // modified here
	gr.setLimit(1);
	gr.query();
	if(gr.hasNext())
		return true;
	else
		return false;
}

Please mark my respsone as helpful/correct, if it answer your question.

Thanks