- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have requirement to make the catalog item visible only based on below conditions
1. User should be member of "XYZ" group AND
2. User should not have manager assigned.
How to do this? Anyone can help me on this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
if the logged in user is not member of that group and the next line tries to get the manager then it will throw error
try this logic
var inGroup = false;
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('user', user_id);
grMem.addQuery('group.name', 'XYZ'); // Exact match; use sys_id for precision
grMem.query();
if (grMem.hasNext()) {
inGroup = true;
}
var hasManager = false;
var userRec = new GlideRecord('sys_user');
if (userRec.get(user_id)) { // Use built-in user_id for user criteria
if (userRec.manager.toString().nil() == false) { // Safe manager check
hasManager = true;
}
}
answer = inGroup && !hasManager;
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Yakshitha,
You can handle this using user criteria.
Create a User Criteria record with:
Group = XYZ (this ensures user is in the group)
In Advanced script, add:
answer = gs.getUser().getRecord().manager.nil();
Let me know if this works!!!!!😉
If you find my answer useful, please mark it as Helpful and Correct. 😊
Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10
