gpt4 book ai didi

javascript有效补丁文件错误

转载 作者:行者123 更新时间:2023-11-29 15:15:52 30 4
gpt4 key购买 nike

尝试在 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":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common, Version=14.0.0.0, Culture=neutral, PublicKeyToken=hidden","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}

我错过了什么?

最佳答案

var area = "TestProject1\\Area 51"; 替换为 var area = "TestProject1\\\\Area 51";

顺便说一下,您在代码中指定了多个区域键。

关于javascript有效补丁文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49133062/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com