Forum Discussion
Mike Jansen
Mar 01, 2017Iron Contributor
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:0x0100AEC702D446F8F0...
Mike Jansen
Mar 01, 2017Iron 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
Mar 02, 2017Iron Contributor
you should have a look at lodash. it has methods to do these kinds of things,
- Mike JansenMar 03, 2017Iron Contributor
Russell Gove I'll look into that when I have some time left. For now I ended up doing some old fashion javascript:
var oldDate = formatDate(results[0].Cells.results[6].Value); for(var i=0;i<results.length;i++){ var newDate = formatDate(results[i].Cells.results[6].Value); if (oldDate == newDate){ TotalMinutes = +TotalMinutes + +results[i].Cells.results[4].Value; } else { var d=new Date(oldDate); [do something] oldDate = formatDate(results[i].Cells.results[6].Value); TotalMinutes = +results[i].Cells.results[4].Value; } } function formatDate(d) { date = new Date(d) var dd = date.getDate(); var mm = date.getMonth()+1; var yyyy = date.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}; return d = mm+'/'+dd+'/'+yyyy }