【问题标题】:Azure DevOps REST API - How are Picklists associated with Field?Azure DevOps REST API - 选项列表如何与字段关联?
【发布时间】:2019-10-04 00:37:01
【问题描述】:

我正在尝试使用 rest 来创建字段和选项列表,在网站上我创建了一个字段作为类型选项列表字符串并将一些项目添加到列表中:

字段的休息网址: https://dev.azure.com/{org}/_apis/work/processes/{processId}/workitemtypes/CMMI2.Bug/fields/Custom.AppType?api-version=5.0-preview.2

它正在返回这个:

{
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"
}

选择列表的休息网址: https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}?api-version=5.0-preview.1 这返回:

{
items: [
"All",
"Item2",
"Item3"
],
id: "{picklistId}",
name: "picklist_{diffGuidFromPickListId}",
type: "String",
isSuggested: false,
url: "https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}"
}

以下是相关文档: https://docs.microsoft.com/zh-cn/rest/api/azure/devops/processes/fields/get?view=azure-devops-rest-5.0#processworkitemtypefield

首先 - 为什么字段字符串的类型应该是picklistString(根据文档链接)?

其次 - 选项列表如何与字段相关联?

谢谢

【问题讨论】:

    标签: rest azure-devops


    【解决方案1】:

    picklistString指的是类型的名称,它的实际属性是string,所以它在type中显示的字段类型是string。

    其次 - 选项列表如何与字段相关联?

    (1) 要实现这一点,可以使用这个API

    POST  https://dev.azure.com/{organizationName}/{projectName}/_apis/wit/fields?api-version=5.1-preview.2
    

    这是我的请求正文供您参考:

    {
      "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
    }
    

    注意:将isPicklist设置为true,您可以将picklist链接到这个新字段。

    (2) UI 操作只需添加新字段,打开type下拉列表,选择picklist(string)/picklist(Integer) 即可。

    picklist(string)picklist(Integer) 的区别在于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

    【讨论】:

    • 感谢您的回复。如何将字段与 UI 中的现有选项列表关联?
    • 哦,对不起。经过与同事进一步研究和讨论,我得到了解决方案。请尝试使用我更新的答案,以查看它是否可以帮助您将选项列表链接到字段。
    • 感谢您的回复,但我有点困惑,我在您的请求正文中没有看到您如何将字段与选项列表相关联?或者将项目添加到该字段的选项列表中?我认为您需要指定选项列表 ID??
    • 还有 - 我如何使用 VssConnection.GetClient 管理这个 api?
    • body中指定filedname,filed和picklist通过isPicklist: true 连接。
    【解决方案2】:

    看起来这一切都没有实际意义,因为 picklistId 属性一旦设置(即在字段创建时)就无法更改。

    在此参考资料中,picklistId 将“否”作为“可以更改吗?”的值专栏:https://docs.microsoft.com/en-us/azure/devops/boards/work-items/work-item-fields?view=azure-devops

    【讨论】:

      猜你喜欢
      • 2020-06-06
      • 1970-01-01
      • 2020-06-12
      • 2021-02-10
      • 1970-01-01
      • 2020-04-08
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多