skip to Main Content

I try do add a field to a work item using this api : https://learn.microsoft.com/en-us/rest/api/azure/devops/processes/fields/add?view=azure-devops-rest-7.1&tabs=HTTP

It work (at least it did accept it, and return te good answer ) !
But the field does not appear in the layout of the work item in the UI, how am i supposed to do that ?

2

Answers


  1. The Fields – Add adds a field definition to your work item type. To add the field to the work item form, check this method: Controls – Create.

    Login or Signup to reply.
  2. Thanks @Shamrai Aleksander, as mentioned by him, you need to add the custom field to one group. Besides, only inherited process supports customization. You can refer to the following PowerShell scripts.

    $token = "{PAT}"
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
    $head = @{ Authorization =" Basic $token" }
    $orgname = "{Organization name}"
    $processId = "{Process id of your custom process}"
    $witRefName = "{The reference name of work item type}" #processname.workitemtype
    $groupid = "Agile.Task.Task.Planning" #The ID of the group to add the control to.
    
    # Add a field named 'CustomField' to work item type 'Task'
    $url1="https://dev.azure.com/$orgname/_apis/work/processes/$processId/workItemTypes/$witRefName/fields?api-version=5.0-preview.2"
    $body1 = @'
    {  
        “referenceName”: “Custom.CustomField”,  
        “type”: “string”,  
        “readOnly”: false,  
        “required”: false,  
        “allowGroups”: null  
    }  
    '@
    Invoke-RestMethod -Uri $url1 -Method Post -Headers $head -Body $body1 -ContentType application/json
    
    # Add custom field 'CustomField' to 'Planning' group
    $url2="https://dev.azure.com/$orgname/_apis/work/processes/$processId/workItemTypes/$witRefName/layout/groups/$groupid/controls?api-version=5.0-preview.1"
    
    $body2 = @'
    {  
        “order”:null,  
        “label”:“CustomField”,  
        “readOnly”:false,  
        “visible”:true,  
        “controlType”:null,  
        “id”:“Custom.CustomField" ,  
        “metadata”:null,  
        “inherited”:null,  
        “overridden”:null,  
        “watermark”:null,  
        “contribution”:null,  
        “height”:null,  
        “isContribution”:false  
    }  
    '@
    
    Invoke-RestMethod -Uri $url2 -Method POST -Headers $head -Body $body2 -ContentType application/json
    

    Then I can see it in Task’s Planning group.
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search