Click here to Skip to main content
13,407,586 members (52,436 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4.5K views
Posted 6 Jul 2016

Visual Studio Team Foundation Service Agile Bugs P2

, 6 Jul 2016
Rate this:
Please Sign up or sign in to vote.
Visual Studio Team Foundation Service Agile Bugs P2

Introduction

This is a second part to my first article. This part will show how to create different types of workitems. Move the Item from the main project list to Iterations or child Iterations.

Work Type Types

With Visual Studio Team Foundation Services, you have the default types of Bugs, Task and User Stories. If you want to use the API to create any of these types, you simply alter the URL as so.

string NewWorkItem = 
"https://[ACCOUNT].visualstudio.com/DefaultCollection/[PROJECT]/_apis/wit/workitems/$[WORKTYPE]?api-version=1.0"
   url = url.Replace("[ACCOUNT]", account);
   url = url.Replace("[PROJECT]", project);

//Alter to create a user story
   url = url.Replace("[WORKTYPE]", "User Story");
//Alter to create a Task
   url = url.Replace("[WORKTYPE]", "Task");
//Alter to create a BUG
   url = url.Replace("[WORKTYPE]", "Bug");

If you create your own, custom types (not 100% sure), but the documents do state that you can. All you need to do is alter the code to include your type.

Move Iterations or Child Iterations

Once you have created the work Item, use the below code to move the items from the root to your new area. This needs a patch call and the below URL and JSON package.

       public static void Add(int workItemId, string areaPath, string iterationPath)
        {
            iteration = iterationPath;
            area = areaPath;
            string UpdateWorkItem = 
            "https://healthdiagnostics.visualstudio.com/DefaultCollection/_apis/wit/workitems/{0}?api-version=1.0"

            string url = String.Format(UpdateWorkItem, workItemId.ToString());
            wiPostDataArr = new List<DataObjectsProject.VSOJasonWorkItemPostData>();

            createInitailItemPostObject();


            Models.Helpers.JASONHelper.Patch(url, httpStringContent, 
            new Models.Helpers.JASONHelper.JSONReturnCallBack(historyLinkReturn));
        }

        private static void createInitailItemPostObject()
        {
            if(!String.IsNullOrEmpty(area))
                AddUpdateProp("/fields/System.AreaPath", area);
            if (!String.IsNullOrEmpty(iteration))
                AddUpdateProp("/fields/System.IterationPath", iteration); 

            httpStringContent = ConvertDataClassToJason(wiPostDataArr);
        }

        private static void AddUpdateProp(string field, object value)
        {
            DataObjectsProject.VSOJasonWorkItemPostData wiPostData = 
            new DataObjectsProject.VSOJasonWorkItemPostData();
            wiPostData.op = "add";
            wiPostData.path = field;
            wiPostData.value = value;
            wiPostDataArr.Add(wiPostData);
        }

//The class object to create the Json package
   public class VSOJasonWorkItemPostData
    {
        public string op;
        public string path;
        public object value;
    }

You can have a look at the application in more detail:

  1. Published version from the online site
  2. See the code within the downloadable
  3. Look at the code within the GitHub repo

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Thomas Cooper
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180221.1 | Last Updated 6 Jul 2016
Article Copyright 2016 by Thomas Cooper
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid