0

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";

5
  • Please share the code that uses the length attribute mentioned in the error code. Commented Sep 28, 2020 at 5:48
  • Also share the whole jqGrid setup and related functions to it. Commented Sep 28, 2020 at 9:14
  • the code failed with api uses result source, returned undefined, guess no result for the api call. jqGrid setup is the same as previous api. Previous api works: var apiUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('documentrequest')/Folders?$expand=ListItemAllFields,AuthorID/id&$select=Name,ItemCount,ListItemAllFields/SubmitterName,ListItemAllFields/ExamName,ListItemAllFields/PublishedDate1,&$filter=Name ne 'Forms' and ItemCount gt 0"; Commented Sep 28, 2020 at 13:34
  • Need to use results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results to retrieve data from the search results document sets are displayed in the JGGrid just fine but the attachments not displayed in jqgrid Commented Oct 1, 2020 at 19:40
  • RequestNameOWSTEXT, SubmittedByOWSUSER,ExaminiationNameOWSTEXT,PublishedDate1OWSDATE are managed properties that are queryable but no value returned from the search api call. search api call returns system columns, like contenttypeId, filename, path but not the custom column values. Commented Oct 3, 2020 at 1:35

2 Answers 2

0

How to debug

  1. You should check if the rest api returns values correctly.
  2. Check whether the type of the variable using length has a length attribute.
Sign up to request clarification or add additional context in comments.

Comments

0

It works, I figured out.. SharePoint search api itself provides only Filename, ContentTypeID, and Path. I use those values to run another api call to get the meta data, then add the values to array, which is used to feed the jqgrid.

Just get all the data into array, then feed to jqgrid when the data is ready.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.