Search code examples
c#tfstfs-workitem

WebAPI-editable readonly field


Is it possible to use Azure DevOps/TFS WebAPI to edit a READONLY workItem field?

I've tried to change the field as usual, but the same way the field is readonly in VisualStudio or the Azure webpage, you can't do the equivalent alteration with an UpdateWorkItem webApi call.

Simplified below:

using (WorkItemTrackingHttpClient wiClient = new WorkItemTrackingHttpClient(new Uri(devOpsServerHost), credentials)) {
    WorkItem wi = wiClient.GetWorkItemAsync(workItemId).Result;

    JsonPatchDocument patchDoc = new JsonPatchOperation[] {
        new JsonPatchOperation()
        {
            Operation = operation, // Add or Replace
            Path = "/fields/Microsoft.VSTS.Scheduling.OriginalEstimate",
            Value = estimated // a float
        }
    });

    return wiClient.UpdateWorkItemAsync(patchDoc, workItemId, bypassRules).Result;
}

I'm trying to get a workItem field to be editable through an external API and to be associated with a user making the changes, while the same user cannot edit the field directly. As an example, user sets several tasks in an external app and the joint estimate is updated into the TFS workItem.

As a bonus I'd like changes to it to not block saving a workItem edition. The readonly field gave me hope, though I believe that might not be possible.


Solution

  • I'm trying to get a workItem field to be editable through an external API and to be associated with a user making the changes, while the same user cannot edit the field directly

    As of this time, however, changing the value of a READONLY work item field through APIs is not currently supported.

    If you make a field READONLY, then it cannot be edited either on the page or through the API.

    An alternative, which may not be so perfect, is to make the field editable programmatically each time you execute the API, and then make it READONLY after editing. You can use the REST API Fields - Update.

    PATCH https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields/{fieldRefName}?api-version=6.0-preview.2
    

    Here is an example request body:

    {
      "readOnly": true
    }