Forum Discussion

ScrumMaster's avatar
ScrumMaster
Copper Contributor
Dec 19, 2022

Updating Parent Link via DevOps API

I am trying to update a DevOps work item parent via the DevOps API.  This work item already has a parent, and I am trying to replace it with a new parent (see ParentId variable below). 

        private JsonPatchDocument CreatePathDocumentParent(Defect defect, string ParentId, bool isNew)
        {
            return new JsonPatchDocument
            {
                new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path = "/relations/-",
                    Value = new
                    {
                        rel = "System.LinkTypes.Hierarchy-Reverse",
                        url = _uri +"/"+ Project + "/_apis/wit/workItems/"+ ParentId,
                        attributes = new
                        {
                            comment = "updated link parent WIT"
                        }
                    }
                },
            };
        }

 
When I run the update as per below, the update does not go through.  I do not get an error or anything of the sort, just the existing parent remains on the work item without any changes:

                JsonPatchDocument patchDocument = CreatePathDocumentParent(defect, parentId, false);

                WorkItem result = _workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, devOpsId).Result;

 
Do I need to use Operation.Replace in my JsonPatchDocument?  Or do I need to remove the existing parent link before adding a new one?  I would really appreciate any syntax suggestions on this one.

No RepliesBe the first to reply

Share

Resources