如何使用Apache Olingo从Microsoft Dynamics扩展OptionSet数据?

时间:2018-10-08 13:48:55

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

我正在使用Apache olingo v4来获取Microsoft Dynamics Data。我正在尝试获取属性扩展为选项集的实体元数据(如果属性的类型为“ Picklist”)。

这是我尝试的示例代码:

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

更新: 我在下面编辑了第三行:

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]

1 个答案:

答案 0 :(得分:0)

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

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

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