The team try to create a custom widget on VSTS that can help to manage group code review. One of the task is to create new work item with type "Code Review Response" and link it to code changes. But the following code does not work:
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
//});
});
}
});
I'm not sure work the problem is. It always give an 400 bad request error and said the referenceName can not be null.
Is there any thing wrong with our code? The 1st parameter of createWorkItem is an document: VSS_Common_Contracts.JsonPatchDocument
. I'm not quite sure how to pass-in this parameter.
Can anyone help on this? Thanks a lot.
The body you sent is incorrect, you are including the work item title in the "relations" and also missed relation type. Please try with following content:
[
{
"op": "add",
"path": "/fields/System.Title",
"value": "xxxx"
},
{
"op": "add",
"path": "/relations/-",
"value":
{
"rel": "ArtifactLink",
"url": "vstfs:///VersionControl/Changeset/xxx"
}
}
]