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

谁能告诉我问题是在dev ops中的设置,还是我的代码(或其他东西)?
//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;使用的命名空间:
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 发布于 2019-05-21 01:53:16
你有一个语法错误,你应该用f写/fields/System.State,而不是用F写Fields。
而改变状态就足够了,原因会自动改变。
发布于 2019-05-21 02:04:30
您的Json最终应该如下所示:
{
"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">
}]
}https://stackoverflow.com/questions/56225651
复制相似问题