尝试在VSTS中创建工作项我成功了。但是,当我想为字段 System.AreaPath 提供值时,我失败了。
我的代码(工作和没有System.AreaPath):
var number = "1234";
var title = "Test Title";
var caller = "Test Caller";
var assignment_group = "Test Group";
var tags = "Bug";
var area = "TestProject1\\Area 51";
var assigned_to = "Test To";
var url = "https://[instance].visualstudio.com/DefaultCollection/TestProject1/_apis/wit/workitems/$Bug?api-version=2.2";
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(url);
request.setHttpMethod('PATCH');
var password = 'somePassword';
request.setBasicAuth(password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json-patch+json');
request.setRequestBody("[{\"op\":\"add\",\"path\":\"/fields/System.Tags\",\"value\":\""+tags+"\"},{\"op\":\"add\",\"path\":\"/fields/System.Title\",\"value\":\"[" + number + "] " + title + "\"},{\"op\":\"add\",\"path\":\"/fields/Microsoft.VSTS.TCM.SystemInfo\",\"value\":\"Assignment Group: "+assignment_group+"\nCaller: "+caller+"\nAssigned to: "+assigned_to+"\"}]");
var response = request.execute();
// {\"op\":\"add\",\"path\":\"/fields/System.AreaPath\",\"value\":\""+area+"\"}
代码包括{\"op\":\"add\",\"path\":\"/fields/System.AreaPath\",\"value\":\""+area+"\"}
var number = "1234";
var title = "Test Title";
var caller = "Test Caller";
var assignment_group = "Test Group";
var tags = "Bug";
var area = "TestProject1\\Area 51";
var assigned_to = "Test To";
var url = "https://[instance].visualstudio.com/DefaultCollection/TestProject1/_apis/wit/workitems/$Bug?api-version=2.2";
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(url);
request.setHttpMethod('PATCH');
var password = 'somePassword';
//,{\"op\":\"add\",\"path\":\"/fields/Microsoft.VSTS.Common.Priority\",\"value\":\"" + priority + "\"}
request.setBasicAuth(password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json-patch+json');
request.setRequestBody("[{\"op\":\"add\",\"path\":\"/fields/System.AreaPath\",\"value\":\""+area+"\"},{\"op\":\"add\",\"path\":\"/fields/System.AreaPath\",\"value\":\""+area+"\"},{\"op\":\"add\",\"path\":\"/fields/System.Tags\",\"value\":\""+tags+"\"},{\"op\":\"add\",\"path\":\"/fields/System.Title\",\"value\":\"[" + number + "] " + title + "\"},{\"op\":\"add\",\"path\":\"/fields/Microsoft.VSTS.TCM.SystemInfo\",\"value\":\"Assignment Group: "+assignment_group+"\nCaller: "+caller+"\nAssigned to: "+assigned_to+"\"}]");
var response = request.execute();
// {\"op\":\"add\",\"path\":\"/fields/System.AreaPath\",\"value\":\""+area+"\"}
给出错误:
{“$ id”:“1”,“innerException”:null,“message”:“你必须传递一个有效的 补丁文件在体内 请求 “” typeName的。 “:” Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common,Version = 14.0.0.0, 文化=中性, 公钥=隐藏”, “typeKey”: “VssPropertyValidationException”, “的errorCode”:0 “事件ID”:3000}
我错过了什么?
答案 0 :(得分:1)
将var area = "TestProject1\\Area 51";
替换为var area = "TestProject1\\\\Area 51";
。
顺便说一下,你在代码中指定了多个区域键。