Verify User Criteria using a script

Sashi K1
Kilo Guru

Hi there

whats the simplest way to verify User Criteria when KB is searched using a script. GlideRecordSecure only applies ACL verification during query run time, how about checking User Criteria too while searching KB articles using script.

For example, script below searches all matching articles applying ACLs on it

getKnowledge();

function getKnowledge() {

        //Query all active records from IT or HR type articles (custom fields) which are valid        

        var query = "workflow_state=published^u_knowledge_typeINIT,HR^active=true^metaLIKEbenefits^textLIKEholiday";

        var kb = new GlideRecordSecure('kb_knowledge');

        kb.addEncodedQuery(query);

        kb.addQuery('valid_to', '>=', (new GlideDate()).getLocalDate().getValue());

        kb.query();

        gs.info('WDPR KB Search : Number of records found >>>>'+kb.getRowCount());   //prints matching records

        while (kb.next()) {   // verifies the ACL at this point of time with given GlideRecordSecure

                  //DO whatever

        }

}

How the same script could be modified to add 'User Criteria Check on each article'? I know querying kb_uc_can_read_mtom table across each Knowledge Base may provide some info, but wanted a simplest API way to quickly verify like canRead() etc

thoughts?

3 REPLIES 3

Adam Lankford
Tera Guru

Sashi,



What exactly is the business requirement for what you are trying to accomplish with the script?


Hi Adam


thanks for responding. The business requirements, is perform a search by script and get count on matching criteria. Say a User is performing a search using 'search string' across KB base, we need to return count of matching records in a script.



Now User ABC performs a count, uses Zing search to find matching records and count, script returns count. How to do we apply User Criteria that is defined across KB Articles at run time? If user ABC is trying, how to we enforce UC for each record returned in search



Sashi


Hi Sashi,



To clarify, this may be made easier by understanding that user criteria are not enforced on each article in the knowledge base. They are applied to the knowledge base itself. Searches honor the user criteria that are applied. As a user, I don't necessarily care what user criteria are applied.