User Criteria

harry24
Tera Contributor

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 ?

@Anurag Tripathi  

Thanks 

7 REPLIES 7

Najmuddin Mohd
Mega Sage

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.

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;

})();

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.





renuka_kulkarni
Tera Contributor

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.