0
votes

I'm using the VSTS REST API to get the iterations of a certain project. What I'm trying to figure out is the "Current iteration".

 var vstsConnection = new VssConnection(new Uri(VstsUrl), new VssBasicCredential(string.Empty, VstsPAT));
            var witClient = vstsConnection.GetClient<WorkItemTrackingHttpClient>();
//get current iteration in VS
            var iterations = witClient.GetClassificationNodeAsync(project: VstsProject, structureGroup: Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.TreeStructureGroup.Iterations, depth: 5).Result;


 // i could iterate over the iterations but i'll just get the first one for now..      
            var attributes = iterations.Children.FirstOrDefault().Attributes;

Here the attributes give me only the startdate and finishdate. What I'm interested is in the "timeframe" to tell me if it's current or future.

Through calling the https://dev.azure.com/{organization}/{project}/{teamid}/_apis/work/teamsettings/iterations

I do get the 3 fields:

{"count":3,"value":[{"id":"f2ac8484-de34-4d5c-8838-cd388a952257","name":"Iteration 1","path":"Web And Mobile Team - Project Documentation\\Iteration 1","attributes":{"startDate":"2018-12-24T00:00:00Z","finishDate":"2018-12-31T00:00:00Z","timeFrame":"current"},"url":"https://url/_apis/work/teamsettings/iterations/f2ac8484-de34-4d5c-8838-cd388a952257"},{"id":"f57903a8-22e5-474a-a450-a7401a53511e","name":"Iteration 2","path":"Web And Mobile Team - Project Documentation\\Iteration 2","attributes":{"startDate":null,"finishDate":null,"**timeFrame**":"future"},"url":"url/_apis/work/teamsettings/iterations/f57903a8-22e5-474a-a450-a7401a53511e"},{"id":"2cfc4be3-0665-46de-81e0-0302138bd276","name":"Iteration 3","path":"Web And Mobile Team - Project Documentation\\Iteration 3","attributes":{"startDate":null,"finishDate":null,"**timeFrame**":"future"},"url":"url/_apis/work/teamsettings/iterations/2cfc4be3-0665-46de-81e0-0302138bd276"}]}

Any help would be appreciated.

2

2 Answers

0
votes

Try this examples:

string projectName = ""; // your project
string teamName = null; //change it for nondefault team 

var WorkClient = Connection.GetClient<WorkHttpClient>();
TeamContext tcx = new TeamContext(projectName, teamName);

TeamSetting tmsettings = WorkClient.GetTeamSettingsAsync(tcx).Result; // current iteration without dates

Console.WriteLine("Current Iteration: {0} - {1}", tmsettings.DefaultIteration.Name, tmsettings.DefaultIteration.Path);

List<TeamSettingsIteration> iterations = WorkClient.GetTeamIterationsAsync(tcx).Result;  // full information for iterations

foreach (TeamSettingsIteration iteration in iterations)
     Console.WriteLine("{0}: {1} : {2}-{3}", iteration.Attributes.TimeFrame, iteration.Name, iteration.Attributes.StartDate, iteration.Attributes.FinishDate);

TeamSettingsIteration currentiteration = (WorkClient.GetTeamIterationsAsync(tcx, "Current").Result).FirstOrDefault(); // get only current

if (currentiteration != null) Console.WriteLine("Current iteration - {0} : {1}-{2}", currentiteration.Name, currentiteration.Attributes.StartDate, currentiteration.Attributes.FinishDate);
0
votes

In the REST Api you can add the attribute $timeframe=current and you will get the current iteration:

https://dev.azure.com/{organization}/{project}/{teamid}/_apis/work/teamsettings/iterations?$timeframe=current&api-version=4.0