LoveToCode-0935 avatar image
0 Votes"
LoveToCode-0935 asked LoveToCode-0935 commented

Creating work items using and JSON.

Hi, I'm working on a desktop application to create work items using Where I find myself stuck is on how to use the JSON document object and it's properties (operations values and elements)

Below is my code. Any help is much appreciated.

 Imports Microsoft.VisualStudio.Services.Common
 Imports Microsoft.VisualStudio.Services.WebApi.Patch.Json
 Imports Microsoft.VisualStudio.Services.WebApi.Patch
 Imports Microsoft.VisualStudio.Services.WebApi
 Imports Microsoft.TeamFoundation.WorkItemTracking.WebApi
 Imports System.Net
 Imports System.Net.Http.Headers
 Imports Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models
 Imports Microsoft.VisualStudio.Services
 'Imports Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchDocument
 'Imports Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClientBase
 'Imports Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClient
 Public Class Form1
     Public _Uri As String
     Public OrgName As String
     Public _Personalaccesstoken As String
     Public _Projectname As String
     Private w As Object
     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         OrgName = ""
         _Personalaccesstoken = "pattoken"
         _Projectname = "testproject"
         'VssBasicCredential credentials = New VssBasicCredential("", _Personalaccesstoken)
         Dim credentials = New VssBasicCredential("", _Personalaccesstoken)
         Dim JPDocument As New JsonPatchDocument
         'With JPDocument                             [ here I don't know what to do ]
         '    .Item(1).Operation = Operation.Add
         '    .Item(1).Path = "/fields/System.Title"
         '    .Item(1).Value = "Visual basic rocks"
         'End With
         Dim _Uri = New Uri(OrgName)
         Dim c As New VssConnection(_Uri, credentials)
         Dim wclient As New WorkItemTrackingHttpClient(_Uri, credentials)
         wclient = c.GetClient(Of WorkItemTrackingHttpClient)
             Dim w As WorkItem
             w = wclient.CreateWorkItemAsync(JPDocument, _Projectname, "Epic").Result
         Catch ex As Exception
         End Try
     End Sub
 End Class

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered LoveToCode-0935 commented


Take a look at ApplyTo (which is how to perform an update), a decent description and example

 Public Class ContactsController
     Inherits Controller
     Private contact As New Contact With {
         .FirstName = "Ben",
         .LastName = "Foster",
         .Age = 30,
         .Links = New List(Of String) From {""}
     Public Function Patch(<FromBody> ByVal ContactPatch As JsonPatchDocument(Of Contact)) As IActionResult
         Dim patched = contact.Copy()
         ContactPatch.ApplyTo(patched, ModelState)
         If Not ModelState.IsValid Then
             Return New BadRequestObjectResult(ModelState)
         End If
         Dim model = New With {
             Key .original = contact,
             Key .patched = patched
         Return Ok(model)
     End Function
 End Class

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm now confused. I followed a c# version for 'Desktop' and it worked so I tried to translate it into and that's where I get problems on using the JSON op methods etc.

I'm creating a destop application. Excuse my lack of knowledge please.

0 Votes 0 ·

We surely can not guess what the problems are so best to share in full details.

0 Votes 0 ·

We have internal projects which are used by our customers (externals) . As per policy we like to isolate certain information from our customers - such as hiding or making certain fields read only in a work item. So far this is accomplished by adding custom rules in azure devops.

What we ran into is how to hide the Link tab of a work item or how to hide the History tab so customers aren't able to see the history.

So I'm working on a project to accomplish the rest. I had worked in vb before so thought to leverage it.

Any suggestions / help is appreciated.


0 Votes 0 ·