public void GetWorkItems() { JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "2nd Work Item Created Using REST Client" } }; WorkItem wi = WitClient.CreateWorkItemAsync(patchDocument, TeamProject.Name, DefaultWorkItemType.Name).Result; WorkItemsAdded.Add(wi.Id.Value); // GetWorkItemsAsync can only return 200 items at a time, so only take the first 200 of the work items list. // Larger lists will require batching calls to GetWorkItemsAsync until the list is processed. List <WorkItem> workItems = WitClient.GetWorkItemsAsync(WorkItemsAdded.Take(200)).Result; foreach (var workItem in workItems) { Console.WriteLine($"{workItem.Id}: '{workItem.Fields["System.Title"]}'"); } Console.WriteLine(); }
public void CreateWorkItem() { JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "Work Item Created Using REST Client" }, new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AssignedTo", Value = Connection.AuthorizedIdentity.DisplayName } }; try { WorkItem wi = WitClient.CreateWorkItemAsync(patchDocument, TeamProject.Name, DefaultWorkItemType.Name).Result; WorkItemsAdded.Add(wi.Id.Value); Console.WriteLine($"Created a work item with id: '{wi.Id}' and title: '{wi.Fields["System.Title"]}'"); } catch (AggregateException ex) { Console.WriteLine("Error creating workitem: '{0}'", ex.InnerException.Message); } finally { Console.WriteLine(); } }
public WorkItem CreateWorkItem(string pProjectName, string pWorkItemType, Dictionary <String, String> pFields, string pParentUrl) { JsonPatchDocument _patchDocument = new JsonPatchDocument(); foreach (var _key in pFields.Keys) { _patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + _key, Value = pFields[_key] }); } _patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = TFFields.LinkParent.RefName, url = pParentUrl, attributes = new { comment = "From service" } } } ); return(WitClient.CreateWorkItemAsync(_patchDocument, pProjectName, pWorkItemType).Result); }
public void ValidateWorkItem() { try { // Create new work item var createPatchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.History", Value = "Modify system history" } }; // Set validateOnly param to true and attempt to create a work item with an incomplete patch document (missing required title field). var validateOnCreateWI = WitClient.CreateWorkItemAsync(createPatchDocument, TeamProject.Name, DefaultWorkItemType.Name, true).Result; } catch (AggregateException ex) { Console.WriteLine(ex.InnerException.Message); Console.WriteLine(); } // Update existing work item try { var wi = WitClient.GetWorkItemAsync(WorkItemsAdded.First()).Result; var updatePatchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AreaPath", Value = "Invalid area path" } }; // Set validateOnly param to true and attempt to update a work item with an invalid field entry. var validateOnUpdateWI = WitClient.UpdateWorkItemAsync(updatePatchDocument, wi.Id.Value, true).Result; } catch (AggregateException ex) { Console.WriteLine(ex.InnerException.Message); Console.WriteLine(); } Console.WriteLine(); }
public Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem CreateWorkItem(string ProjectName, string WorkItemTypeName, Dictionary <string, object> Fields) { JsonPatchDocument patchDocument = new JsonPatchDocument(); foreach (var key in Fields.Keys) { patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + key, Value = Fields[key] }); } return(WitClient.CreateWorkItemAsync(patchDocument, ProjectName, WorkItemTypeName).Result); }
public void LinkExistingWorkItem() { // Get existing work item to link to new work item. WorkItem existingWI = WitClient.GetWorkItemAsync(WorkItemsAdded.First()).Result; // Create a patch document for a new work item. // Specify a relation to the existing work item. JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "New work item to link to" }, new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "System.LinkTypes.Hierarchy-Reverse", url = existingWI.Url, attributes = new { comment = "adding a link to an existing work item" } } } }; // Create a new work item and link it to the existing work item (using patchdocument) WorkItem newWI = WitClient.CreateWorkItemAsync(patchDocument, TeamProject.Id, DefaultWorkItemType.Name).Result; Console.WriteLine($"Created a new work item Id:{newWI.Id}, Title:{newWI.Fields["System.Title"]}"); foreach (var relation in newWI.Relations) { Console.WriteLine($"{relation.Rel} {relation.Title} {relation.Url}"); } Console.WriteLine(); }