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

Musab Rasheed
Tera Sage
Tera Sage

Always remember to paste what you have written ? Anyways please add below code to advance section and also check 'Match all' check to true

find_real_file.png

Code:

answer = checkIfManager();

function checkIfManager(){

var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();

return gr.hasNext();

}
Please hit like and mark my response as correct if that helps
Regards,
Musab

I have written the same code. It is not working if location is also selected

Screenshot ?

Please hit like and mark my response as correct if that helps
Regards,
Musab

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use script to cover all cases

answer = checkCondition();

function checkCondition(){
	var gr = new GlideRecord("sys_user");
	gr.addQuery("manager", user_id);
	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;

}

Regards
Ankur

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