Help with query and list field

Alon Grod
Tera Expert

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);

6 REPLIES 6

MrMuhammad
Giga Sage

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);
Regards,
Muhammad

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;
Regards,
Muhammad

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.

 

Jaspal Singh
Mega Patron
Mega Patron

Hi Alon,

I believe the issue with with NQ in EncodedQuery

Please go through link for a check.