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

palanikumar
Mega Sage

Hi @Samiksha2 

Hope you replaced the first line as below

var userss = gs.getUserID();
Thank you,
Palani

Hi @palanikumar ,
In user criteria gs.getUserID() doesnt work.

Samiksha2_0-1729857992809.png

Thanks,
Sam

Kieran Anson
Kilo Patron

Are you running the background script in global, and is the user criteria created in global? Using .getDisplayValue is restricted in scoped applications. I'd also recommend against basing the criteria on the display value of a record that can change but instead on the sys_id(s).