Share via

Creating new workitems (VB.net ) using json

LoveToCode 161 Reputation points
2021-04-26T06:33:46.19+00:00

Hi, I'm creating new work items (devops) using vb.net. I can create a single work item with just a single property but when I try to add a second property I don't see the work item getting created at all. Below is my code.

               Dim JSDocument = New JsonPatchDocument
                Dim JDocOpearion = New JsonPatchOperation

                JSDocument.Add(JDocOpearion)

                With JDocOpearion
                    .Path = "/fields/System.Title"
                    .Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add

                    .Value = Txt_WITTitle.Text
                End With

/* If I comment the below upto End With I can see a single work item */

                JSDocument.Add(JDocOpearion)
                With JDocOpearion

                    .Path = "/fields/System.Description"
                    .Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add
                    .Value = "This is a description"
                End With

                Dim a As Object
                a = WClient.CreateWorkItemAsync(JSDocument, "Destination Project", "Epic")
Developer technologies | VB
0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2021-04-26T07:28:13.73+00:00

Try adding JDocOpearion = New JsonPatchOperation before the second JSDocument.Add(JDocOpearion).

(Also consider reordering the statements, executing JSDocument.Add after creating and filling the operation objects).

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

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