Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

User criteria match all on location and group

Daniela18
Tera Contributor

Hi

I want a user criteria to both match user group and a location that is on the user.

But this doesn't work. Do I have to script? I am novice at scripting, How would such a script look?

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

I would encourage to have step by step debug

1) check if member of Hardware is able to access the catalog

Keep Script as: Test with user

answer = gs.getUser().isMemberOf('Hardware');

Next

2) check if user's location condition is satisfied

Keep Script as: Test with user having that location

answer = ifScript();

function ifScript(){

var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();

var locationValid = user.hasNext();

return locationValid;

}

3) Now combine both the codes and check by adding logs

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

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

View solution in original post

19 REPLIES 19

not working. baah this is driving my crazy and seems crazy hard

Hi,

I would encourage to have step by step debug

1) check if member of Hardware is able to access the catalog

Keep Script as: Test with user

answer = gs.getUser().isMemberOf('Hardware');

Next

2) check if user's location condition is satisfied

Keep Script as: Test with user having that location

answer = ifScript();

function ifScript(){

var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addQuery('location', '25ab9d720a0a0bb300793d3a6b891f82');
user.query();

var locationValid = user.hasNext();

return locationValid;

}

3) Now combine both the codes and check by adding logs

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Regards
Ankur

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

Thank you. I now tried again and it finally worked

Jaspal Singh
Mega Patron

Hi Daniela,

 

Juse ensure below.

find_real_file.png

Else, it will try to match any of condition from above & then display it.

Yes. I've already made sure.