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 Task <Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem> UpdateWorkItem(int WIId, 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.UpdateWorkItemAsync(patchDocument, WIId)); }
public void UpdateExistingWorkItem() { var wi = WitClient.GetWorkItemAsync(WorkItemsAdded.First()).Result; var originalTitle = wi.Fields["System.Title"]; JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "Changed Work Item Title Using REST Client" } }; var result = WitClient.UpdateWorkItemAsync(patchDocument, wi.Id.Value).Result; Console.WriteLine($"Workitem: '{wi.Id}' title updated from: '{originalTitle}' to: '{result.Fields["System.Title"]}'"); Console.WriteLine(); }