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);
url = url.Replace("[WORKTYPE]", "User Story");
url = url.Replace("[WORKTYPE]", "Task");
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);
}
public class VSOJasonWorkItemPostData
{
public string op;
public string path;
public object value;
}
You can have a look at the application in more detail:
- Published version from the online site
- See the code within the downloadable
- Look at the code within the GitHub repo