I want to display knowledge article based on user language

Adarsh kumar si
Tera Contributor

There is one requirement to show knowledge article to users only of their language on ESC portal (i.e. If user language is Dutch / French then Kb Article should only be visible by user on ESC portal) .  We are using Widget "Knowledge featured articles" to display the articles.

As per current OOB Users are able to see the articles from different language as well.

Can anyone help me on achieve this requirement?


Thank you

2 REPLIES 2

Dr Atul - LNG
Tera Patron

https://www.servicenow.com/community/developer-forum/displaying-kb-articles-according-to-the-languag... 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0868940

 

Instructions

You can dynamically set the article language based on the user preferred language by setting a dynamic default value into the language field dictionary.


This can be done by following the steps below:

Create a 'Dynamic Filter Option' record to get the 'preferred_language' for the current user.

  1. Go to 'System Definition > Dynamic Filter Options' and create a new record.Add a label such 'User Preferred Language'.
  2. If you want to use the language selected at the user profile (sys_user_preference), simply set the 'Script' field with 'user.language'.
  3. If you want to use the 'Preferred Language' set in the user record (sys_user), then set the 'Script' field to query the user preferred language i.e.: gs.getUser().getRecord().getValue('preferred_language');
  4. Set the field type to 'String'.
  5. Save it.


Update the dictionary to use the above 'Dynamic Filter Option'.

  1. Open the 'language' sys_dictionary record related to the 'kb_knowledge' table.
  2. Find the 'Default Value' tab and check the 'Use dynamic default' option.
  3. In the 'Use dynamic default' select the 'Dynamic Filter Option' record you just created.
  4. Save it.

 

Now next time a user creates a new article, the article language will be set based on the user preferred language.
If the user has no preferred language set, then the language will be set to empty in the article.

Another option is to create a client script that will automatically set the knowledge language based on the user language.
You can use the 'g_lang' variable to get the user language i.e.: g_form.setValue('language',g_lang);

In that case, for the client script to work you may need to add the 'Language' field into the knowledge form.