G.S Abhaypal G.S Abhaypal - 4 years ago 331
JSON Question

VSTS Task Creation : Required field missing

I am trying to create task in

VSTS
, but I am getting the below error.


TF401320: Rule Error for field Task Type. Error code: Required, HasValues, LimitedToValues, AllowsOldValue, InvalidEmpty.


From
Exception
it is clear that I am missing a required field which is
Task Type
. Now I am not able to find the field path for
Task Type
. Can anyone help me with this.

Below is the code I am writing to add a task :

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;

Answer Source

You may add Task Type field to Task work item, but don’t add to the layout.

enter image description here

You can check fields of Task work item in Web Access (Go to collection page > Settings >Process >Select template >Work Item Types >Task >Fields) or through REST API.

Setting value of Task Type field:

Code:

    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"
        });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download