I would like to programatically link WorkItems to Changesets.
At the moment I am already creating work items from my c# code and saving them to the TFS. The code looks as follows:
WorkItem item = new WorkItem(project.WorkItemTypes["CustomItem"]);
item.Fields["CustomField1"].Value = someValue;
item.Fields["CustomField2"].Value = someValue;
item.Fields["CustomField3"].Value = someValue;
item.Validate();
item.Save();
This part of the code works fine. Now I would like to associate the newly created work item to an existing changeset. I am getting the changeset using:
VersionControlServer service = collection.GetService<VersionControlServer>();
Changeset changeset = service.GetChangeset(123123, true, true);
However, I can only iterate through the existing work items. I cannot add a new work item to this changeset. Does anyone have an idea how to achieve this?
I found out how to do this by trail-and-error method:
WorkItemStore store = new WorkItemStore(collection);
Changeset changeset = service.GetChangeset(123, true, true);
WorkItem item = new WorkItem(project.WorkItemTypes["CustomItem"]);
item.Links.Add(new ExternalLink(store.RegisteredLinkTypes[ArtifactLinkIds.Changeset], changeset.ArtifactUri.AbsoluteUri));
item.Fields["CustomField1"].Value = someValue;
item.Fields["CustomField2"].Value = someValue;
item.Fields["CustomField3"].Value = someValue;
item.Validate();
item.Save();
I hope this will help someone else in the future! :)
Christian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With