Saving WorkItem # IterationPath for a newly created iteration

I can successfully create an iterative path with:

var commonservice = collection.GetService<ICommonStructureService>(); // create new area path and iteration path var iterationRoot = commonservice.GetNodeFromPath("\\MyTeamProject\\Iteration"); var newIterationPath = commonservice.CreateNode("my new sprint", iterationRoot.Uri); 

However, when I try to assign this path to a work item and save it, the field is not checked.

If I run the tests again (with an iteration already created), the same code will succeed.

Does anyone know how to make this work?

+4
source share
4 answers

This is fixed for me:

 WorkItemStore wis = (WorkItemStore)tfsTeamProjColl.GetService(typeof(WorkItemStore)); wis.RefreshCache(); wis.SyncToCache(); 

Maybe this will help someone.

+3
source

I experienced exactly the same behavior, and unfortunately @JWC's answer did not help. A solution that works for me can be found at this link .

So, this is a brief summary in case of loss of the original answer.

The key point is to use the WorkItemServer class. He lives in the Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll assembly.

First of all, you create an instance of WorkItemStore :

 var store = collection.GetService<WorkItemStore>(); 

Then create the necessary iteration paths:

 var commonservice = collection.GetService<ICommonStructureService>(); var iterationRoot = commonservice.GetNodeFromPath("\\MyTeamProject\\Iteration"); var newIterationPath = commonservice.CreateNode("my sprint", iterationRoot.Uri); 

Then update the cache in TFS (I suspect this is similar to pressing F5 in the web interface):

 var wiServer = collection.GetService<WorkItemServer>(); wiServer.SyncExternalStructures(WorkItemServer.NewRequestId(), commonservice.GetProjectFromName("MyTeamProject").Uri); store.RefreshCache(); 

And finally, assign the newly created work item the newly created iteration:

 var wi = new WorkItem(store.Projects["MyTeamProject"].WorkItemTypes["Product Backlog Item"]); wi.Title = "Hello from API"; wi.Description = "This work item was created from API"; wi.Fields["Assigned To"].Value = "Yan Sklyarenko"; wi.IterationPath = FormatPath(commonservice.GetNode(newIterationPath).Path, "Iteration", "MyTeamProject"); wi.Save(); 

What is it! The FormatPath method takes the iteration path to the form required by the IterationPath work item field, from \MyTeamProject\Iteration\my sprint to MyTeamProject\my sprint .

Hope this can save some time.

NOTE. I am running this for TFS 2013.

+2
source

You are probably facing a caching issue. Try clearing the cache after creating an iteration. A few things you could try:

  • Get a new copy of WorkItemStore.
  • Disconnect and reconnect to TFS
  • Check if there is an upgrade method in WIS or on TFS server objects. I closed my dev instance from TFS overnight, and I donโ€™t remember if I liked anything.

If this is not entirely true, submit your code and I will see if I can reproduce it.

0
source

I had a similar problem. I created Areapath and then created a query that used AreaPath. I actually called store.RefreshCashe (), but that did not work. Only in Debugger when I run store.RefreshCashe () twice manually. Thanks to Jan Sklyarenko. I tried your suggestion and it works great (TFS Server 2012).

0
source

Source: https://habr.com/ru/post/1310427/


All Articles