Click here to Skip to main content
15,886,873 members
Articles / Web Development / HTML
Tip/Trick

Visual Studio Team Foundation Service Agile Bugs P2

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
6 Jul 2016CPOL 7.6K  
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.

C#
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.

C#
       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)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --