'Azure DevOps Access Custom Field From Script

I have a required custom field on any ticket created (Bug, Tasks, PBI).

I have a pipeline that creates tickets automatically, but the values that are used to create these tickets doesn't have a value for my custom field. I want to set this custom field by adding an entry to the pipeline variables, but I don't know the variable name of the custom field.

How can I find the variable name of the custom field so I can access it?



Solution 1:[1]

I found out how to determine your custom variable name.

ADO has a bunch of APIs. The following will give you all the details of a specific work type. For my case I needed the "bug" work type.

/* 
    Api to display work type fields in JSON format
    Replace {} with correct values
*/

https://dev.azure.com/{orginization}/{project}/_apis/wit/workitemtypes/{type}/fields?api-version=6.0

The resulting JSON will give you a whole list of variables. Here is what the System Variable and a Custom Variable look like.

enter image description here

The referenceName is the variable name you would use in your scripts, etc.

TL;DR - Take your field name and remove all spacing and then put Custom. in front of it.

Custom.FieldNameWithNoSpace

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ZombieCode