VSTS任务创建:缺少必填字段

时间:2017-02-01 14:46:02

标签: c# json azure-devops azure-devops-rest-api

我正在尝试在VSTS中创建任务,但我收到以下错误

  

TF401320:字段任务类型的规则错误。错误代码:必需,HasValues,LimitedToValues,AllowOldValue,InvalidEmpty。

Exception来看,很明显我错过了必填字段Task Type。现在我无法找到Task Type的字段路径。任何人都可以帮助我。

以下是我要编写的用于添加任务的代码:

string discipline = "Research Task";

if (taskDesc.Key.Contains("Configuration"))
{
    discipline = "Dev Task";
}
if (taskDesc.Key.Contains("Validation"))
{
    discipline = "Quality Task";
}

var workitemtype = "Task";
var document = new JsonPatchDocument();
document.Add(
    new JsonPatchOperation()
    {
        Path = "/fields/Microsoft.VSTS.Common.Discipline",
        Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
        Value = discipline
    });
document.Add(
    new JsonPatchOperation()
    {
        Path = "/fields/System.Title",
        Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
        Value = string.Format("{0} {1}", porIDText, taskDesc.Key)
    });
document.Add(new JsonPatchOperation()
{
    Path = "/fields/System.AreaPath",
    Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
    Value = System.Configuration.ConfigurationManager.AppSettings["AreaPath"]
});
document.Add(
    new JsonPatchOperation()
    {
        Path = "/fields/System.AssignedTo",
        Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
        Value = "<name>"
    });
document.Add(
    new JsonPatchOperation()
    {
        Path = "/fields/System.Description",
        Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
        Value = taskDesc.Value
    });
var wi = client.CreateWorkItemAsync(
document,
teamProjectName,
workitemtype).Result;

1 个答案:

答案 0 :(得分:1)

您可以将“任务类型”字段添加到“任务”工作项,但不要添加到布局。

enter image description here

您可以在Web Access中检查任务工作项的字段(转到集合页面&gt;设置&gt;处理&gt;选择模板&gt;工作项类型&gt;任务&gt;字段)或通过REST API。< / p>

设置任务类型字段的值:

代码:

    document.Add(
        new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation()
        {
            Path = "/fields/Microsoft.VSTS.CMMI.TaskType",
            Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
            Value = "Type1"
        });