Question

I have a KeywordQuery in JavaScript. The items returned are by date ascending. How can I change this to date descending?

var keywordQuery = new SharePoint.Client.Search.Query.KeywordQuery(clientContext);

var searchExecutor = new SharePoint.Client.Search.Query.SearchExecutor(clientContext);

keywordQuery.set_queryText(query); 

result = searchExecutor.executeQuery(keywordQuery);
Was it helpful?

Solution

You can enable sorting using below

keywordQuery.set_enableSorting(true); 
var sortproperties = keywordQuery.get_sortList();
sortproperties.add("Write", 1); //0 = Ascending
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top