Knowledge

harry24
Tera Contributor

Hello , 

 

How to write script in user criteria so that if their is an article in German language then the knowledge author and owner of that article can view the article irrespective of whatever is their language?

if (userGR.preferred_language == 'de'|| current.u_owner == gs.getUserID() || current.author==gs.getUserID()) {
return true;
}

 

this script is partially working 

Thanks 

 

23 REPLIES 23

Also I have just realized you are using current.
There is no current in User Criteria.
In fact the default script has a comment that explicitly states:

 

/*
 * ...
 * Don't use `current` in the script or populate the variable
 * ...
 */

 

The way you expect here it is not how User Criteria work; those are evaluated once on login and cached and later when an access needs verification, the system checks whether the current user has in cache any of the needed User Criteria.
The exception is with catalog item User Criteria that can be configured to be evaluated on each catalog page load.
I would say you need to redesign the solution so that it does not rely on current... as it does not exist.

harry24
Tera Contributor

So how do I fulfill my requirement?how to achieve it ?how can I modify the criteria so that kb owners and authors have access to their article irrespective of whatever language it is.please help

KB0790108  has more detailed technical information on how User Criteria and caching is working.

@harry24 

then update as this

var userGR = new GlideRecord('sys_user');
userGR.get(user_id);
if (userGR.preferred_language.toString() == 'de') {
    answer = true;
} else if (current.u_owner == user_id || current.author == user_id) {
    answer = true;
} else
    answer = false;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader