How to get the KB Category Page widget to sort the Knowledge Articles by the KB article's created by date?

atlsdrew
Kilo Contributor

I'm trying to update a KB Category Page widget and sort by created by date.  Any help would be greatly appreciated!

2 REPLIES 2

VigneshMC
Mega Sage

Below Thread with similar requirement should be helpful

 

https://community.servicenow.com/community?id=community_question&sys_id=bf6b4f21db9cdbc01dcaf3231f96190a&anchor=answer_a6f1d4b9db545fc01dcaf3231f961926&view_source=searchResult

 

Thanks

Swathi12
Tera Expert

Hi,

You can follow below approach :

Clone the widget : KB Category Page

Add : {"hint":"The query to filter the result","name":"filter_query","default_value":"","label":"Filter Query","type":"string"} in option schema

In HTML template :

1. Add a selection criteria : Created By (ASC/DESC)- For the user to select the sorting in ascending and descending, use ng-click and call a client function 

Note : you can caret-up and caret-down for ex : <i class="fa fa-lg fa-caret-down">

In client script : Write the client function in which the user input.orderType will passed to server script using c.server.get

In Server script of the widget:

if(input) 

Write a function :

function xyz(orderType) {
var filter = options.filter_query + '';
return filter + (filter == ''? '' : '^') + 'ORDERBY' + (orderType.order_desc? 'DESC' : '') +sys_created_on';
}

Fetch the input.orderType(which consists of the order -asc/desc selected by the user) and pass this into the function created above

Instead of data.items = $sp.getKBCategoryArticleSummaries(data.category, 0, 250); use new KBViewModel().getDiffKBCategoryArticleSummaries(data.category, curLoad, loadLimit, 250, query); where in query is the result of function  xyz(orderType).

 

I hope this will solve your issue , do let me know in case of any queries.

 

Regards,

Swathi