0

I am using the TFS 2018 Rest API to create Work Items.

I can create a Work Item, but I wanted it to go to a specific column on the board.

I tried to pass the following parameter when I will create a Work Item, to configure the column:

  {
    "op": "add",
    "path": "/fields/System.BoardColumn",
    "from": null,
    "value": "Waiting worker"
  }

When I make a Patch request to insert a work item with the code above, I receive the following return:

{
    "$id": "1",
    "customProperties": {
        "ReferenceName": null
    },
    "innerException": null,
    "message": "TF401326: Invalid field status 'ReadOnly' for field 'System.BoardColumn'.",
    "typeName": "Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemFieldInvalidException, Microsoft.TeamFoundation.WorkItemTracking.Server",
    "typeKey": "WorkItemFieldInvalidException",
    "errorCode": 600171,
    "eventId": 3200
}

How can I do to include a Work Item on a specific board?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
Wesley
  • 245
  • 6
  • 13
  • Have you checked the reply below? If it helps you, you could [Accept it as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), this can be beneficial to other community members reading this thread. – Cece Dong - MSFT Jun 17 '20 at 09:22

1 Answers1

0

To update the board column you should update another field, not the System.BoardColumn (he's read-only).

Which field? According to Microsoft Docs, you should investigate the fields, and you will see this kind of field:

WEF_432678B52358ACDA34ASDA243489FD343_Kanban.Column

So you should find the field for the work item you just created and update the field:

WorkItem workItem = this.CreateWorkItem("Board Column Test", "User Story");

string wefField = "";

// By the way - I opened PR to improve it, still waiting for the approval...
foreach (var field in workItem.Fields)
{               
    if (field.Key.Contains("_Kanban.Column"))
    {
        wefField = field.Key.ToString();
        break;
    }
}

patchDocument.Add(
     new JsonPatchOperation()
     {
          Operation = Operation.Add,
          Path = "/fields/" + wefField,
          Value = targetColumn
     }
);

WorkItem result = witClient.UpdateWorkItemAsync(patchDocument, Convert.ToInt32(workItem.Id)).Result;
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114