Matching values in list field using query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 12:42 PM
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.
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.
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 12:47 PM
HELLO
CAN YOU TRY WITH THIS SCRIPT
(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.toString(); //excluded accounts in user record
in_accounts = gr.u_include_account.toString(); //included accounts in user record
}
var query = 'u_accountISEMPTY^NQu_accountLIKE'+in_accounts +'^NQu_accountNOTLIKE'+ex_accounts;
current.addEncodedQuery(query);
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:28 AM
not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:37 AM
hello
just a quick doubt if the exclude and include accounts are are of LIST type fields which stores. multiple values 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.toString(); //excluded accounts in user record
in_accounts = gr.u_include_account.toString(); //included accounts in user record
}
var query = 'u_accountISEMPTY^NQu_accountIN'+in_accounts +'^NQu_accountNOTIN'+ex_accounts;
current.addEncodedQuery(query);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 08:38 AM
if it worked please close the thread by marking the answer correct so that it goes to solved queue