首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用WorkItemTrackingHttpClient更新WorkItem状态

无法使用WorkItemTrackingHttpClient更新WorkItem状态
EN

Stack Overflow用户
提问于 2019-05-21 01:30:49
回答 2查看 1.3K关注 0票数 2

我正在自动更新工作项工时,但忽略对状态的更改。我想将状态从“活动”设置为“已解决”。

我发现有信息表明,如果您要更改状态,则还需要设置一个“原因”,但我的代码没有更改原因或状态,尽管所有其他字段更新都在工作。我怀疑这是因为状态字段是只读的,但我们找不到这样的规则(我们使用的是CMMI模板):

谁能告诉我问题是在dev ops中的设置,还是我的代码(或其他东西)?

代码语言:javascript
复制
//Executing from LINQPad, no need to mention the blocks on async....

WorkItem targetWorkItem = client.GetWorkItemAsync(123456).Result;    

JsonPatchDocument patchDocument = new JsonPatchDocument();

patchDocument.Add(
    new JsonPatchOperation()
    {
        Operation = Operation.Replace,
        Path = "/fields/Microsoft.VSTS.Scheduling.CompletedWork",
        Value = 123
    }
);

patchDocument.Add(
    new JsonPatchOperation()
    {
        Operation = Operation.Replace,
        Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork",
        Value = 0
    }
);

/*
    These don't work! I think because "Reason" field is read only
*/
patchDocument.Add(
    new JsonPatchOperation()
    {
        Operation = Operation.Add, //Tried Replace as well as Add
        Path = "/Fields/System.Reason",
        Value = "Complete and Requires Review/Test"
    }

patchDocument.Add(
    new JsonPatchOperation()
    {
        Operation = Operation.Add, //Tried Replace as well as Add
        Path = "/Fields/System.State",
        Value = "Resolved"
    }
);

//Succeeds for any field except Status and Reason
WorkItem result = client.UpdateWorkItemAsync(patchDocument, 123456).Result;

使用的命名空间:

代码语言:javascript
复制
Microsoft.TeamFoundation.WorkItemTracking.WebApi  
Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models  
Microsoft.VisualStudio.Services.Common  
Microsoft.VisualStudio.Services.WebApi  
Microsoft.VisualStudio.Services.WebApi.Patch  
Microsoft.VisualStudio.Services.WebApi.Patch.Json 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-21 01:53:16

你有一个语法错误,你应该用f/fields/System.State,而不是用FFields

而改变状态就足够了,原因会自动改变。

票数 3
EN

Stack Overflow用户

发布于 2019-05-21 02:04:30

您的Json最终应该如下所示:

代码语言:javascript
复制
{
     "id": xx,
     "rev": yy,
     "fields": [{
         "field": {
             "refName": "System.State"
         },

         "value": "Resolved"
     },
     {
         "field": {
             "refName": "System.Reason"
         },

         "value": "Status Reason"
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ActivatedBy"
         },

         "value": null
     },

     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ActivatedDate"
         },

         "value": null
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ResolvedDate"
         },

         "value": "2014-08-25T19:14:04.594Z"
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ResolvedBy"
         },

         "value": "User Name"
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ResolvedReason"
         },

         "value": "Resolved Reason"
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ClosedDate"
         },

         "value": <null or "2014-08-25T19:14:04.594Z">
     },
     {
         "field": {
             "refName": "Microsoft.VSTS.Common.ClosedBy"
         },
         "value": <null, "John Doe">
     }]
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56225651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档