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

@harry24 

it won't work as you don't have access to current object and hence cannot determine the Owner or Author

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

what is the solution then ?

 

You persist in NOT copying correctly the suggestions.

You keep writing == gs.getUserID() while community members keep writing == user_id.

You only correct the 1st occurrence, but all must be corrected.

 

In User Criteria script - as specified in the comments for a new User Criteria script, one must not use gs.getUserID(), one must use user_id. Otherwise the check will be done against the user owning the current session, which might not be the user you expect to be. For sure it will render the User Criteria diagnostic tool useless.

 

Also one must be careful when testing the User Criteria, those are cached on login (or impersonation), so after each change a cache flush is advisable. Are you flushing the cache before each test run?

harry24
Tera Contributor

Corrected but it is still not working 

Can you run the User Criteria Diagnostic over the article and post a screenshot of the result?

 

Example:

2024-12-31_001.png