Unable to successfully generate work item through VSO SDK

A team is attempting to develop a custom widget on VSTS to facilitate group code reviews. One of the tasks is to create a new work item with the type "Code Review Response" and link it to code changes. However, the current code is not functioning as expected:

import WorkitemRestClient = require("TFS/WorkItemTracking/RestClient");
var workitemClient = WorkitemRestClient.getClient();

var c = VSS.getWebContext();

import VersionCtrlRestClient = require("TFS/VersionControl/TfvcRestClient");
var versionCtrlClient = VersionCtrlRestClient.getClient();

versionCtrlClient.getChangesets(c.project.name)
.then(changesets => {
    for (var i = changesets.length - 1; i >= 0; i--) {
        var content = $("#content");
        content.append("<pre>" + JSON.stringify(changesets[i].comment, null, "\t") + "</pre>");

        workitemClient.createWorkItem([{
            "op": "add",
            "path": "/relations/-",
            "value": {
                "rel": "",
                "title": "xxxx",
                "url": changesets[i].url
            }
        }], c.project.name, "Code Review Response")
            .then(workitem => {
                //workitem.relations.push({
                //    "attributes": { "key": [] },
                //    "rel": "",
                //    "title": "",
                //    "url": changesets[i].url
                //});
            });
    }
});

The issue is not clear. It consistently returns a 400 bad request error indicating that the referenceName cannot be null. Is there an error in our code? The first parameter of createWorkItem requires a

document: VSS_Common_Contracts.JsonPatchDocument
, but I am unsure how to correctly pass this parameter. Could anyone offer assistance? Thank you.

Answer №1

It appears that there was an error in the body you submitted. The work item title should not be included in the "relations" section, and you also forgot to specify the relation type. Please use the following corrected content:

[
    {
        "op": "add",
        "path": "/fields/System.Title",
        "value": "xxxx"
    },
    {
        "op": "add",
        "path": "/relations/-",
        "value":
        {
            "rel": "ArtifactLink",
            "url": "vstfs:///VersionControl/Changeset/xxx"
        }
    }
]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring data from the server to the client side in Next JS with the help of getInitialProps

I am currently developing an application using nextJS. Within server/index.ts, I have the following code: expressApp.get('/', (req: express.Request, res: express.Response) => { const parsedUrl = parse(req.url, true); const { query } = ...

How can I run a TypeScript function within a JavaScript file?

I am working with a typescript file named file1.ts export function Hello(str: string) { console.log(str); } In addition, I have another file called index.js { require('./some.js'); } Furthermore, there is a script defined in the pack ...

Retrieving Identifiers with Typescript from an object

I'm a newcomer to Typescript and I'm looking to extract ids from an observable Here's the observable data: let myObj = [{ "id": 1, "text": "Mary" }, { "id": 2, "text": "Nancy" }, { "id": 3, "text": "Paul" }, { "id": 4, "tex ...

What are the steps to troubleshoot server-side TypeScript code in NextJS with WebStorm?

I am struggling to debug the NextJS API in WebStorm while using TypeScript and navigating through the app route. It is proving to be quite challenging to efficiently debug the API without relying heavily on console.log(). ...

"Navigate to another screen with the FlatList component upon press, displaying specific

I've created a flatlist of countries with a search filter using an API. I need help implementing a feature where clicking on a country's name in the list redirects to a screen that displays the country's name and number of cases. The screen ...

Using interfaces for typecasting in TypeScript

Consider the code snippet below: let x = { name: 'John', age: 30 } interface Employee { name:string, } let y:Employee = <Employee>x; console.log(y); //y still have the age property, why What is the reason for TypeScript ov ...

What causes TypeScript to overlook the generic constraint within a function?

Here is a simple illustration of what I am trying to convey: type Shape = 'square' | 'circle'; type Params<S extends Shape> = S extends 'square' ? { side: number } : { radius: number }; function getArea<S ...

Does a <Navigate> exist in the react-router-dom library?

Within the parent component import LoginPage from "pages/admin"; export function Home() { return <LoginPage />; } Inside the child component import { useRouter } from "next/router"; export default function LoginPage() { co ...

Dealing with Unexpected Timeout Errors and Memory Leaks in Express/Typescript Using Jest, Supertest, and TypeORM

Currently, I am in the process of writing unit tests for an express API. Each test suite initiates a fresh instance of an express server before running the tests. Individually, each test suite runs smoothly without any problems. However, when executed tog ...

Can you explain the significance of { 0: T } in this particular type definition?

I stumbled upon this type declaration in my codebase which is meant for non-empty arrays: type NonEmptyArray<T> = T[] & { 0: T } and it functions as expected: const okay: NonEmptyArray<number> = [1, 2]; const alsoOkay: NonEmptyArray<n ...

React with TypeScript: The struggle of getting LocalStorage to work

Currently, I am dealing with persistence in a todo application developed using React and TypeScript. To achieve the desired persistence, I have implemented localStorage. Allow me to share some code snippets: const [todos, setTodos] = useState<todoMod ...

Implementing CAPTCHA V2 on Angular encounters an Error: It requires the essential parameters, specifically the sitekey

Encountering an issue adding Recaptcha V2 to a simple Angular Page, my knowledge in Angular is limited. The HTML file and component.ts file are referenced below. Attempting to send this form along with the token to a Laravel API for validation, and return ...

Encountering a Static Injector error in Angular 5 while trying to inject a component from a shared module

Here lies the code for my component file. My goal is to develop a reusable modal component using ng-bootstrap's modal feature. However, upon trying to import the following component from the shared module, I encounter a static injector error. Despite ...

How to retrieve the parent activated route in Angular 2

My route structure includes parent and child routes as shown below: { path: 'dashboard', children: [{ path: '', canActivate: [CanActivateAuthGuard], component: DashboardComponent }, { path: & ...

The identifier 'before' could not be located

While working with jest and typescript, I encountered an issue when using "before" calls: Cannot find name 'before'.ts(2304) I made sure to have @types/jest installed already. Update: It appears that jest does not have a "before" function - it ...

What is the process for modifying object information using string input in typescript?

How can I update an object's value in TypeScript based on a string input related to the object key? const objData = { // random value A: 11, B: 13, C: 53, innerObj: { AStatus: true, BStatus: false, CStatus: true, }, }; type Item ...

Tips for addressing the browser global object in TypeScript when it is located within a separate namespace with the identical name

Currently diving into TypeScript and trying to figure out how to reference the global Math namespace within another namespace named Math. Here's a snippet of what I'm working with: namespace THREE { namespace Math { export function p ...

Error with the type of CanvasGradient in the NPM package for converting text to image

I attempted to generate an image using a specific text by utilizing npm's text-to-image package, but encountered an error during typescript compilation. The errors I encountered upon running the typescript compilation command are related to files with ...

What is the most effective method for locating and modifying the initial instance of an element within a group?

In my Javascript/Typescript collection, I have the following items: [ {"order":1,"step":"abc:","status":true}, {"order":2,"step":"xyz","status":true}, {"order":3,"step":"dec","status":false}, {"order":4,"step":"pqr","status":false}, {"order":5,"step":" ...

What is the best way to utilize the Moment.js TypeScript definition file in a website that already has moment.min.js integrated?

Currently, I am in the process of transitioning a website to utilize TypeScript by converting one JavaScript file at a time. All pages on my site are already linked to moment.js, such as: <script src="/scripts/moment.min.js"></script> I have ...