User Criteria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 02:37 AM
Hello ,
I have user criteria set for knowledge articles .
for example if german users than in script it checks if the users preferred language is german than it shows the article .
Now the problem is say suppose their is a user Abel Tutor whose preferred language is English . Their is one article KB0015321 which has can read set to all german users . Now though abel tutor is owner of article but still he is not able to view it as his preferred language is english . How do I modify my script ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 02:45 AM
Hi @harry24 ,
You can add one more condition, if knowledge.owner is gs.getUserId() in the script.
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 04:07 AM
How to dynamically set the addQuery()? Below is my script
(function checkLanguage() {
var userGR = new GlideRecord('sys_user');
if (userGR.preferred_language == 'de') {
return true;
}
return false;
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 06:01 AM
function checkLanguage() {
var userGR = new GlideRecord('sys_user');
if (userGR.preferred_language == 'de' || current.kb_knowledge_base.owner == gs.getUserID()) {
return true;
}
return false;
})();
Hi @harry24
Can you check the above script with one more condition :
current.kb_knowledge_base.owner == gs.getUserID()
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 02:46 AM
var userLang = gs.getUser().preferred_language; // Get user's preferred language
var article = new GlideRecord('kb_knowledge');
if (article.get('sys_id', 'KB0015321')) { // Replace with actual article sys_id
// Allow access if user is the owner or has German as the preferred language
if (article.owner == gs.getUserID() || userLang == 'de') {
return true;
}
// Check if article is for all German users
if (article.can_read == 'all_german_users' && userLang == 'de') {
return true;
}
// Deny access otherwise
return false;
}
Explanation:
- Ownership Check: article.owner == gs.getUserID() ensures that the article owner can always view the article.
- Language Check: userLang == 'de' ensures that German users can access articles marked for German users.
- This way, Abel Tutor (even if their preferred language is English) will be able to view the article if they are the owner, while others are restricted by language.