How to write a script section in USER CRITERIA for access to knowledge base;

ganesh68
Kilo Contributor

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.

10 REPLIES 10

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn