【问题标题】:How to expand OptionSet data from Microsoft Dynamics using Apache Olingo?如何使用 Apache Olingo 从 Microsoft Dynamics 扩展 OptionSet 数据?
【发布时间】:2018-10-08 13:48:55
【问题描述】:

我正在使用 Apache olingo v4 来获取 Microsoft Dynamics 数据。我正在尝试获取实体元数据,其属性随选项集一起扩展(如果属性是“选择列表”类型)。

这是我尝试过的示例代码:

URIBuilder absoluteUri = client.newURIBuilder("<URL>").appendEntitySetSegment("EntityDefinitions");
absoluteUri.filter("LogicalName eq 'account'");            
absoluteUri.expand("Attributes($expand=OptionSet)");
URI uri = absoluteUri.build();
ODataRawRequest request = client.getRetrieveRequestFactory().getRawRequest(absoluteUri);
request.setAccept("application/json;odata.metadata=full");
ODataRawResponse response = request.execute();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> result = mapper.readValue(response.getRawResponse(), new TypeReference<Map<String, Object>>(){});
return mapper.convertValue(result.get("value"), new TypeReference<List<Map<String,Object>>>(){});

当我运行它时,我收到以下错误:

org.apache.olingo.client.api.communication.ODataClientErrorException: (0x0) Could not find a property named 'OptionSet' on type 'Microsoft.Dynamics.CRM.AttributeMetadata'."Could not find a property named 'OptionSet' on type 'Microsoft.Dynamics.CRM.AttributeMetadata'." [HTTP/1.1 400 Bad Request]

我如何使用 Olingo 做到这一点?如果我必须通过邮递员这样做,我可以点击这个网址

 GET [Organization URI]/api/data/v9.0/EntityDefinitions(LogicalName='account')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$expand=OptionSet

更新: 我将第 3 行编辑为以下内容:

absoluteUri.expand("Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata($expand=OptionSet)");

得到以下错误:

org.apache.olingo.client.api.communication.ODataClientErrorException: (0x0) Found a path traversing multiple navigation properties. Please rephrase the query such that each expand path contains only type segments and navigation properties."Found a path traversing multiple navigation properties. Please rephrase the query such that each expand path contains only type segments and navigation properties." [HTTP/1.1 400 Bad Request]

【问题讨论】:

    标签: dynamics-crm olingo dynamics-crm-webapi


    【解决方案1】:

    也许你应该更新第三行如下:

    absoluteUri.expand("Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata($expand=OptionSet)");
    

    错误消息是 Microsoft.Dynamics.CRM.AttributeMetadata 而不是 PicklistAttributeMetadata

    【讨论】:

    • 嗨@Arun 我试过了,但是得到了这个错误:org.apache.olingo.client.api.communication.ODataClientErrorException: (0x0) 找到了一个遍历多个导航属性的路径。请改写查询,使每个展开路径仅包含类型段和导航属性。“找到遍历多个导航属性的路径。请改写查询,使每个展开路径仅包含类型段和导航属性。” [HTTP/1.1 400 错误请求]
    • 如果我直接从邮递员那里点击 URL,这将有效。我在使用 Olingo 时遇到问题,我认为我们无法在 olingo 中使用“/”进行导航。
    • 我需要说——在属性为 PicklistAttributeMetadata 类型的属性中展开 OptionSet
    • @Surajhk 但您在邮递员和 olingo 中没有使用相同的请求。即 PicklistAttributeMetadata vs AttributeMetadata
    • 在 olingo 我不能说 Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata($expand=OptionSet),什么相当于 /Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$expand=OptionSet 在 olingo ?
    猜你喜欢
    • 2022-07-14
    • 2023-03-16
    • 2019-06-04
    • 2011-11-11
    • 2021-11-22
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多