User criteria is not working for Knowledge bases

Samiksha2
Mega Sage

Hi all,

I have a requirement to show knowledge bases based on the Business Line.

Business line(List collector - referencing to Business Line table) is in Contact table(customer_contact).

I have created a User criteria and added in the Can read tab of Knowledge base. 
My script is

var userss = user_id;
var con = new GlideRecord('customer_contact');
con.addEncodedQuery('accountISNOTEMPTY');
con.addQuery('sys_id', userss);
con.query();
if (con.next()) {
    var names = con.u_bl_contact.getDisplayValue();
    if ((names == "ABC, XYZ") || (names == "XYZ, ABX")) {
        answer = true;
    } else {
        answer = false;
    }
}

In the background script I am getting the true /false values.
But when I added it in the User criteria it is not working.

Please let me know what I am doing wrong.

22 REPLIES 22

There is the below line which expects a single sys_id value only: 

con.addQuery('sys_id', userss);

and you can delete it

 

you can merge the 2 query conditions as follows:

con.addEncodedQuery('accountISNOTEMPTY^sys_idIN' +  userss);

Hi @Antoni Zahariev ,
I tried with the Encoded Query nothing working. yeah it seems like it is working for only one value. but in my case have to check both values.
Its frustrating..
Thanks,
Sam

Hi @Samiksha2 

Try this for the variable userss:

 

 

var userss = new GlideRecord('sys_user');
userss.get(user_id);

 

 

I'll try to reproduce here as well.

EDIT:
Try this way on your script:

var con = new GlideRecord('customer_contact');
con.addEncodedQuery('accountISNOTEMPTY');
con.addQuery('sys_id', userss);
con.query();
if (con.next()) {
        if ((con.getDisplayValue('u_bl_contact').toLowerCase().indexOf('ABC') >= 0 ||
          con.getDisplayValue('u_bl_contact').toLowerCase().indexOf('XYZ') >= 0 || 
          con.getDisplayValue('u_bl_contact').toLowerCase().indexOf('ABX') >= 0 || {
        answer = true;
    } else {
        answer = false;
    }
}