Forum Discussion

Mike Jansen's avatar
Mike Jansen
Iron Contributor
Mar 01, 2017

Sharepoint online - search/rest api -filter results in URL

I've got this piece of code to query a certain content type:

	var results = [];
  		$.ajax({
    		url: "https://blabla.sharepoint.com/_api/search/query?querytext='ContentTypeId:0x0100AEC702D446F8F04696C2B7573837C451*'&trimduplicates=false&rowlimit=500&selectproperties='FullName%2cWorkHours%2cWorkDate'",
    		method: "GET",
    		headers: {"accept": "application/json;odata=verbose"},
			success: function(xData, request){
            results = xData.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;

This is working fine. But, as you can see it gives me all records (which can be a lot). In my current solution I build an If statement to filter "FullName" on the Current User. It works but performance wise is doe not seem the best solution. So I would like the initial query to give me only the records of the current user.

 

 

I tried several queries like this:

 

url: "https://blabla.sharepoint.com/_api/search/query?querytext='ContentTypeId:0x0100AEC702D446F8F04696C2B7573837C451*'&trimduplicates=false&rowlimit=500&selectproperties='FullName%2cWorkHours%2cWorkDate'?$filter FullName eq CurrentUser",

In all kind of different ways. But no luck so far.

 

 

When I have this in place I also would like to aggegate the hours per day.  But that will be phase two ;-)

 

Can someone help me out?

4 Replies

  • Mike Jansen's avatar
    Mike Jansen
    Iron Contributor

    I figured it out:

     

        		url: "https://bla.sharepoint.com/_api/search/query?querytext='ContentTypeId:0x0100AEC702D446F8F04696C2B7573837C451*'&selectproperties='FullName%2cWorkHours'&refinementfilters='FullName:equals(%22"+ VarName +"%22)'",
    • Mike Jansen's avatar
      Mike Jansen
      Iron Contributor

      Now I would like to sort and sum my data based on the date.

      A user enters his working hours on different projects a day.

       

      I my query I sort on the date. This returns something like "Wed Mar 1 15:14:44 UTC +100 2017"

      All I need is to sum all hours with (for example) date "Wed Mar 1". I tried to do some loops again but that doen not look very good, performance wise (again).

       

      Did someone ever do something like this before?

      • Russell Gove's avatar
        Russell Gove
        Iron Contributor
        you should have a look at lodash. it has methods to do these kinds of things,

Resources