Work item - how to add a related / child workitem in vb.net

LoveToCode 161 Reputation points
2021-04-26T10:03:33.113+00:00

Hi, how can I add a linked / child workitem in vb.net. Below is my piece of code. - updated, I'm using the WorkItemLinks class. I also get an error on the source property that it's set to null.

      JDocOpearion = New JsonPatchOperation

            With JDocOpearion
                .Path = "/relations/-"
                .Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add
                Dim link = New WorkItemLink
                .Value = link.Rel = "System.LinkTypes.Hierarchy-Reverse" _
                & link.Source.Url = witlink.Source.Url


            End With

            JSDocument.Add(JDocOpearion)
Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LoveToCode 161 Reputation points
    2021-04-27T07:44:12.227+00:00

    I figured it out. here's what I did. @Viorel . Please suggest if there's also a better way to do. I love to code. Thank you :)

          JDocOpearion = New JsonPatchOperation  
      
                    Dim SRCWitem As New WorkItem  
                    Dim WitRelations As New WorkItemRelation  
      
                    SRCWitem = WitClient.GetWorkItemAsync(SourceWorkItemID).Result  
      
                    WitRelations.Rel = "System.LinkTypes.Hierarchy-Reverse"  
                    WitRelations.Title = "Azure devops"  
                    WitRelations.Url = SRCWitem.Url  
      
                    With JDocOpearion  
                        .Path = "/relations/-"  
                        .Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add  
                        .Value = WitRelations  /* I added the workitemrelations object */  
                    End With  
                    JSDocument.Add(JDocOpearion)  
      
                    Dim a As Object  
                    a = WitClient.CreateWorkItemAsync(JSDocument, ProjectName, "Epic")  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.