How to set the languages in alphabetical order on a KB article in portal

Nagasri
Tera Expert

Nagasri_0-1749649584040.png

How to set this in alphabetical order. Anyone Please help here

1 REPLY 1

Abbas_5
Tera Sage
Tera Sage

Hello @Nagasri,

 

To display KB article languages in alphabetical order within a ServiceNow Service Portal, you can modify the Knowledge Feature widget or the widget used to display the language listYou can do this by sorting the language data either on the server-side (in the server script) or client-side (using a client script). 
 
1. Identify the Widget:
  • If you are using the standard Knowledge Feature widget, you can adjust its settings.
  • If you have a custom widget, you'll need to modify its code. 
2. Sort the Language Data:
  • Server-side Sorting (Recommended):
    • Open the widget in the ServiceNow platform. You can do this by right-clicking on the widget in the portal and selecting "Open in Platform."
    • Locate the server script. This script is responsible for fetching and preparing the language data.
    • Add a sorting query. Use the orderBy parameter in the query to sort the language data alphabetically by the language name field. For example, orderBy: +name will sort in ascending order by the "name" field.
    • Test and Deploy: After making changes, test the sorting in the portal and deploy the changes to the production environment.
  • Client-side Sorting:
    • Open the widget in the ServiceNow platform.
    • Locate the client script.
    • Add the sorting code. You can use a client-side script to sort the c.data.items array, which contains the language data. For example: c.data.items.sort((a, b) => a.name.localeCompare(b.name));.
    • Test and Deploy: After making changes, test the sorting in the portal and deploy the changes to the production environment. 
       
3. Example (Server-side Sorting):
// Inside the server scriptvar kbArticles = new GlideRecord('kb_knowledge');kbArticles.addQuery('knowledge_base', 'knowledge_base_sys_id'); // Replace with your knowledge basekbArticles.setLimit(100); // Adjust as neededkbArticles.orderBy("name"); // Sort by namekbArticles.query();var result = [];while (kbArticles.hasNext()) {    kbArticles.next();    result.push(kbArticles);}c.data.items = result;
4. Testing and Deployment:
  • After implementing your chosen method, test the sorting in the portal.
  • Ensure the languages are displayed in alphabetical order.
  • Deploy the changes to the production environment once you are satisfied with the results. 

If this is helpful, please hit the thumbs button and accept the correct solution by referring to this solution in future it will be helpful to them.

 

Thanks & Regards,

Abbas Shaik