问题
I am trying to use rest to create fields and picklists, on the web site I created a field as type picklist String and added some items to the list:
Rest url for field: https://dev.azure.com/{org}/_apis/work/processes/{processId}/workitemtypes/CMMI2.Bug/fields/Custom.AppType?api-version=5.0-preview.2
it is returning this:
{
referenceName: "Custom.AppType",
name: "AppType",
type: "string",
description: "",
url: "https://dev.azure.com/{org}/_apis/work/processes/bd96307e-3d16-44ac-b498-be1a8daff2d5/behaviors",
customization: "custom"
}
Rest URL for picklist: https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}?api-version=5.0-preview.1 this returns:
{
items: [
"All",
"Item2",
"Item3"
],
id: "{picklistId}",
name: "picklist_{diffGuidFromPickListId}",
type: "String",
isSuggested: false,
url: "https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}"
}
Here is documentation for this: https://docs.microsoft.com/zh-cn/rest/api/azure/devops/processes/fields/get?view=azure-devops-rest-5.0#processworkitemtypefield
Firstly - why is type of field string when it should be picklistString (as per documentation link)?
Secondly - how is the picklist linked to the field?
thanks
回答1:
The picklistString refers to the name of the type, its actual property is string, so the field type it displays in type is string.
Secondly - how is the picklist linked to the field?
(1) To achieve this, you can use this API:
POST https://dev.azure.com/{organizationName}/{projectName}/_apis/wit/fields?api-version=5.1-preview.2
Here is my request body for you reference:
{
"name": "{FieldName}",
"referenceName": "{the reference name of WIT},
"type": "string",
"usage": "workItem",
"readOnly": false,
"canSortBy": true,
"isQueryable": true,
"supportedOperations": [
{
"referenceName": "{the reference name of WIT}"
"name": "="
}
],
"isIdentity": true,
"isPicklist": true,
"isPicklistSuggested": false,
"url": null
}
Note: Set isPicklist as true
, and you can link picklist to this new field.
(2) For UI operation, just add new field, open the drop-down list of type and select picklist(string)/picklist(Integer) as what you need.
The difference between picklist(string)
and picklist(Integer)
is that picklist(string) allow a pick list of short text string (255 characters or less) values, and picklist(Integer) contains a pick list of Integer values.
回答2:
It would appear that this is all moot, since the picklistId
property cannot be changed once it has been set (i.e. at field creation).
In this reference material, picklistId
has "No" as its value for the "Can change?" column: https://docs.microsoft.com/en-us/azure/devops/boards/work-items/work-item-fields?view=azure-devops
来源:https://stackoverflow.com/questions/56173532/azure-devops-rest-api-how-are-picklists-associated-with-field