1

I am try to create a new JsonPatchDocument as below ,

let PatchDoc = new JsonPatchDocument();

But Above is not possible as JsonPatchDocument is a interface in typescript. Can anyone help how can this be done ???

I created using let PatchDoc : JsonPatchDocument;

If i do so , i am not able to add the data to JsonPatchDocument PatchDoc .add( { op: "add", path: "/fields/System.Priority" , value: "1" })

It says add does not exists on type JsonPatchDocument

Anusha B
  • 95
  • 1
  • 1
  • 8

1 Answers1

0

Refer to this code below:

import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';

var collectionUrl = "https://xxxxxx.visualstudio.com";

let token: string = "Yourpersonalaccesstoken";

let creds = vm.getPersonalAccessTokenHandler(token);

var connection = new vm.WebApi(collectionUrl, creds); 

let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();

async function getWI() {
    let wiid: number = 1;
    let workitem: wi.WorkItem = await vstsWI.getWorkItem(wiid);

    console.log(workitem.url);
}

getWI();

async function createWI() {
    let wijson: vss.JsonPatchDocument = [{ "op": "add", "path": "/fields/System.Title", "value": "Task created from Node JS" }];
    let project: string = "Project";
    let witype: string = "Task";
    let cWI: wi.WorkItem = await vstsWI.createWorkItem(null, wijson, project, witype);
    console.log(cWI.id);
}

createWI();

Related issue: How to create work items using Visual Studio Team Services Client for Node.js (vso-node-api)?

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53