Question

I am trying to develop a SharePoint Online Add-in. I have a simple query that seems to get all of the Events the current user is authorized to see [1]:

var getEventsURL =
    "https://" + hostName + "/" + theSitePath +
    "/_api/search/query?" +
    "querytext='contenttype:Event'";

I run that query with a simple $.ajax call. When the results come back, I get an array of rows in data.d.query.PrimaryQueryResult.ReleventResults.TableRows.results [2]. When I open one of these rows, I see yet another array of 48 values in Cells.results that contains all of the data fields for that row.

In column 3, I see the Title for the current Event. Also in column 7, I see the Description [3]. That's very useful to me but I also need to find the StartDate and EndDate of the Event. Unfortunately, I've looked all through the 48 returned values for the currently iterated Event and I can't find StartDate or EndDate anywhere.

After running a Search Query of the form
https://[serverName]/_api/search/query?queryText='contenttype:Event';
how do I find the DateTimes at which each Event begins and ends?

[1] - Accessing list data in multiple site collections
[2] - http://michaelsoriano.com/understanding-sharepoint-rest-api-part-1-selecting-items/
[3] - Column numbers are zero based

Was it helpful?

Solution

I was able to retrieve the times the events started and stopped by referencing EndDateOWSDATE and EventDateOWSDATE via the selectProperties [1][2] query parameter. My resulting query is:

var getEventsURL =
    "https://" + hostName + "/" + theSitePath +
    "/_api/search/query?" +
    "querytext='ContentClass:STS_ListItem_Events'" +
    "&selectProperties=" +
    "'Title,Description,EndDateOWSDATE,EventDateOWSDATE'";

I also made some changes to the SharePoint Search Schema similar to what is mentioned in [3] but I'm not 100% sure that was necessary.

[1] - https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview#bk_SelectProperties
[2] - https://social.technet.microsoft.com/Forums/Lync/en-US/3b2c39a3-8017-40c0-b866-e1efbf7104ad/how-do-i-query-all-the-managed-properties-available-for-search-results
[3] - https://social.msdn.microsoft.com/Forums/fr-FR/586d4eb5-e090-460e-892d-acfffd7ea489/calendars-fields-eventdate-and-enddate-does-not-appear-in-search-result

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top