locked
Add Tags Programmatically To Work Items

    Question

  • Hello,

    I want to be able to mass update work items with a certain tag programmatically. Is there currently a way to do this? I've checked the workitem class and have seen that there is a tags property that is readonly. Is there another way to accomplish this through code?

    Best,

    Michael

    Wednesday, July 23, 2014 1:38 PM

Answers

  • Hi Michael,  

    Thanks for your post.

    To set tag value for work item using TFS API, please refer to the below code snippet:

    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("Url"));

    tfs.EnsureAuthenticated();

    WorkItemStore workitemstore = tfs.GetService<WorkItemStore>();

    //get work item

    WorkItem wi = workitemstore.GetWorkItem(ID);

    //set Tags' value for this wi

    wi.Fields["Tags"].Value = "MyTag";

    wi.Save();

    Console.WriteLine(wi.Fields["Tags"].Value);


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 24, 2014 3:13 AM
    Moderator
  • Thursday, July 24, 2014 4:48 AM

All replies

  • mmm I'm not sure that you'll be able to do this.

    If you want to bulk update WI, probably Excel is your best chance. 

    Hope this helps!

    Regards!

    Nicolas Zapata 

    http://nicozapata.ctrl365.com

    Wednesday, July 23, 2014 1:57 PM
  • Hi Michael,  

    Thanks for your post.

    To set tag value for work item using TFS API, please refer to the below code snippet:

    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("Url"));

    tfs.EnsureAuthenticated();

    WorkItemStore workitemstore = tfs.GetService<WorkItemStore>();

    //get work item

    WorkItem wi = workitemstore.GetWorkItem(ID);

    //set Tags' value for this wi

    wi.Fields["Tags"].Value = "MyTag";

    wi.Save();

    Console.WriteLine(wi.Fields["Tags"].Value);


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 24, 2014 3:13 AM
    Moderator
  • Thursday, July 24, 2014 4:48 AM
  • That link no longer works. It is now at https://blogs.blackmarble.co.uk/blogs/rfennell/post/2013/05/03/Accessing-TFS-work-item-tags-via-the-API
    Monday, March 6, 2017 7:58 PM