- 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
2 weeks ago
@Ankur Bawiskar
Getting this error "Cannot read property "manager" from undefined"
- 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
2 weeks ago
@Ankur Bawiskar
This script is restricting all the members of "XYZ" group to access catalog item. Its not checking whether the user has manager or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
it should work fine
the 2nd part checks if logged in user has manager or not
If not and user is in member of that group then it allows
did you add gs.info() and debug?
💡 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
2 weeks ago - last edited 2 weeks ago
"Cannot find function nil in object" getting this error
Updated
if (userRec.manager.toString().nil() == false)
to
if (userRec.manager.toString()!="") Its working now. Thank you @Ankur Bawiskar
