Search code examples
c#azure-devopsworkitem

Finding Path of Custom Field in Devops


I'm building a console app that programmatically create Work Item in Azure DevOps. Sofar I have been successful with setting the values to the predetermined field. For example, by executing following code

`

        Uri uri = new Uri(_uri);
        string personalAccessToken = _personalAccessTocken;
        string project = _project;

        // Creating credentials using PAT
        VssBasicCredential credentials = new VssBasicCredential(string.Empty, _personalAccessTocken);

        JsonPatchDocument patchDocument = new JsonPatchDocument();

        //add fields and their values to the patch document
        // See this link below to find out the path of Work Item Field:
        // https://learn.microsoft.com/en-us/azure/devops/boards/work-items/guidance/work-item-field?view=azure-devops

        patchDocument.Add(new JsonPatchOperation()
        {
            Operation = Operation.Add,
            Path = "/fields/System.Title",
            Value = "Test - Please Ignore"
        }`

Here, setting the value was successful due since I could find the path of the Title field (/fields/System.Title) in Microsoft Documentation

However, I came across to a custom field created by the customer named Errormsgtag and I could not manage to set value to it because of the missing path.

The question is: How can I find the path of custom field? Is there any predetermined rules from Microsoft?

Thanks in Advance


Solution

  • There is a rest api where you can request a WorkItemField by it's name and then you have the workitemfielddefinition with the id that you can use -> https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/fields/get?view=azure-devops-rest-5.0

    I think the client-dlls already wrapped this function but i'll have to look up where...