Help with query and list field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:29 AM
Hi,
I am trying to prevent from specific users to see articles in KB by using their exclude and include Account. The goal is to let them see only articles that their account is empty, or the user's exclude account is not in the article's account.
What am I doing wrong?
(function executeRule(current, previous /*null when async*/ ) {
var ex_accounts;
var in_accounts;
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_id=' + gs.getUserID());
gr.query();
while (gr.next()) {
ex_accounts = gr.u_exclude_account; //excluded accounts in user record
in_accounts = gr.u_include_account; //included accounts in user record
}
query = 'u_accountISEMPTY^NQu_accountLIKE' + in_accounts + '^NQu_accountNOT LIKE' + ex_accounts;
current.addEncodedQuery(query);
})(current, previous);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:33 AM
Please try this:
(function executeRule(current, previous /*null when async*/ ) {
var ex_accounts;
var in_accounts;
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('sys_id=' + gs.getUserID());
gr.query();
while (gr.next()) {
ex_accounts = gr.u_exclude_account; //excluded accounts in user record
in_accounts = gr.u_include_account; //included accounts in user record
}
query = 'u_accountISEMPTY^ORu_accountLIKE' + in_accounts + '^u_accountNOT LIKE' + ex_accounts;
current.addEncodedQuery(query);
})(current, previous);
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:48 AM
Above will work for List fields and incase if you have reference fields for included accounts and excluded accounts then your updated query would be
query = 'u_accountISEMPTY^ORu_account=' + in_accounts + '^u_account!=' + ex_accounts;
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:08 AM
Dear Muhammad,
Both answers are not working. Please let me give you more details:
For example, ex_account list will include [A,B].
in_account list will include [C,D,F].
If the article's Account contain: [B]. The user will not be able to see the article.
If the article's Account contain: [Z,P]. The User will be able to see the article.
If the article's Account contain: []. The user will be able to see the article.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:38 AM