How to write a script section in USER CRITERIA for access to knowledge base;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 02:14 AM
I have a article A in my knowledge base. User with a group X. shouldnt have access to the KB article A.
I have written script for the same. Can some one help me whats the issue ?
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', 'user_id');
gr.addQuery('group', '<Sys id of group name>');
gr.query();
if (gr.next()) {
gs.info("User is Member of Group! requester");
answer= true;
} else {
gs.info("User is Not a Member of Group!");
answer= false;
}
this code is not working it seems.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2020 03:13 AM
Looking at your script again, I just noticed:
gr.addQuery('user', 'user_id');
So the 'user_id' part, because of the quotes, it's now a string. Where you are actually after the predefined variable user_id. So just remove the quotes:
gr.addQuery('user', user_id);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field