I tried to see if I can use JQGrid to display SharePoint search results by querying SharePoint result source with REST API.
The code to use REST API to call result source works in browser and Postman:
var apiUrl =_spPageContextInfo.webAbsoluteUrl +/_api/search/query?querytext='Mike'&rowlimit=100&selectproperties='RequestNameOWSTEXT, SubmittedByOWSUSER,ExaminiationNameOWSTEXT,PublishedDate1OWSDATE&sourceId='d90c19xx-7b3x-42bx-8fbx-d1dxxxx543ffa7', many results are returned.
But when I used it in JQGrid, got an error at line 44: Uncaught TypeError: Cannot read property 'length' of undefined
$.ajax({ url: apiUrl,type: "GET", async: false, headers: { "accept": "application/json;odata=verbose" }, success: function (data) {
line 44: $.each(data.d.results, function (index, value) { .............................
I guess the api call doesn't return result so the data is undefined. Wondering is something wrong with that api?
A different api like below works to return results:
var apiUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('documentrequest')/Folders?$expand=ListItemAllFields,AuthorID/id&$select=Name,ItemCount,ListItemAllFields/AuthorId,ListItemAllFields/ExaminiationName,ListItemAllFields/PublishedDate1&$filter=Name ne 'Forms' and ItemCount gt 0";