javascript有效补丁文件错误

标签 javascript azure-devops

尝试在 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/

相关文章:

javascript - 当鼠标移出时如何隐藏元素

azure - 从 Azure Devops 中的中央 GIT 存储库管理 API 管理?

azure - 为什么自动发布后需要手动开启App Insights?

bash - azure 管道模板如何引用位于同一模板存储库中的文件?

javascript - Div 内容可编辑,按 Enter 键时插入新元素

javascript - 将 html 标签作为文本输出到 div 中,每个数组元素在单独的行上

tfs - 有没有办法加快 Visual Studio 团队服务(和 TFS)的构建速度

azure-devops - Azure DevOps : how to disable CI trigger on a YAML template pipeline?

javascript - getElementsByTagName 只获取顶级标签?

javascript - Angular-1 和 Angular-4 在不同 App 中的共存