in analytics-example-widget/scripts/data/ViewQueries.ts [47:86]
public runQuery(): IPromise<GroupedWorkItemAggregation[]> {
return ODataClient.getInstance().then((client) => {
let endDate: string = this.formatDate(this.burndownQueryOptions.endDate);
let startDate: string = this.formatDate(this.burndownQueryOptions.startDate);
let entity = "WorkItemSnapshot";
let teamFilter = `Teams/any(t:t/TeamSK eq ${this.burndownQueryOptions.teamId})`;
let typeFilter = `(WorkItemType eq '${this.burndownQueryOptions.workItemType}')`;
//Apply a filter to select work bounded by the supplied dates
let timeFilter = `(DateValue ge ${startDate}Z and DateValue le ${endDate}Z)`;
let filter = `${teamFilter} and ${typeFilter} and ${timeFilter}`;
if (this.burndownQueryOptions.fields != null && this.burndownQueryOptions.fields.length > 0) {
filter += ` and ${this.makeFilters(this.burndownQueryOptions.fields)}`;
}
let groupFields = `DateSK, StateCategory`;
let selectedAggregation = this.burndownQueryOptions.aggregation;
let aggregationMode = selectedAggregation.aggregationMode;
let aggregationSumValue = selectedAggregation.queryableName;
let aggregation = ``;
if (aggregationMode == AggregationMode.sum) {
aggregation = `${aggregationSumValue} with sum`;
} else {
aggregation = `$count`;
}
aggregation += ` as AggregatedValue`;
let aggregationQuery = `${entity}?$apply=filter(${filter})/groupby((${groupFields}),aggregate(${aggregation}))`;
let fullQueryUrl = client.generateProjectLink(this.burndownQueryOptions.projectId, aggregationQuery);
return client.runGetQuery(fullQueryUrl).then((results: GroupedWorkItemAggregation) => {
return results["value"];
});
});
}