Met*_*rry 7 rest dynamics-crm odata query-string odata-v4
我正在 Dynamics 365 中编写元数据查询,但我认为这个问题对于任何 OData 查询都可能是通用的。
我的问题如下:
在 Dynamics 中,实体中可以有多种类型的字段,例如字符串、布尔值或查找。我想编写一个查询,返回查找正在寻址的实体的类型。
{url}/api/data/v9.0/EntityDefinitions(LogicalName='Account')
?$select=
LogicalName
&$expand=
Attributes(
$select=
LogicalName,
AttributeType,
Targets; -- Problematic property
$filter=
AttributeType+eq+Microsoft.Dynamics.CRM.AttributeTypeCode'Lookup')
Run Code Online (Sandbox Code Playgroud)
如果我在此查询中不包含目标的选择,我会得到正确的结果,即 AttributeType 为 Lookup 的所有属性。
但是当我要求也包含目标时,我收到一条错误消息
Could not find a property named 'Targets' on type 'Microsoft.Dynamics.CRM.AttributeMetadata
Run Code Online (Sandbox Code Playgroud)
由于 Target 属性仅存在于 Lookup 类型的数组中,因此从字符串属性中选择此列将失败并引发此错误。
有没有办法在选择列之前首先过滤查找?我发现这里评估的顺序是
$filter、$inlinecount、$orderby、$skiptoken、$skip、$top、$expand、$select、$format
这正是我所需要的,只是我不认为在 $expand 属性内调用时这个顺序是相同的。
为了获取查找实体,您可能会更幸运地执行$expandonManyToOneRelationships而不是Attributes获取ReferencedEntity值。
像这样的东西应该有效:
.../api/data/v9.1/EntityDefinitions(LogicalName='account')
?$select=LogicalName
&$expand=ManyToOneRelationships($select=ReferencingAttribute,ReferencedEntity)
结果子集:
{“@odata.context”:“ https://myOrg.api.crm.dynamics.com/api/data/v9.1/$metadata#EntityDefinitions(LogicalName,ManyToOneRelationships(ReferencingAttribute,ReferencedEntity))/$entity ”, “LogicalName”:“帐户”,“MetadataId”:“70816501-edb9-4740-a16c-6a5efbc05d84”,“ManyToOneRelationships”:[{“ReferencingAttribute”:“msdyn_accountkpiid”,“ReferencedEntity”:“msdyn_accountkpiitem”,“MetadataId”: "2a712c96-09b1-e811-a842-000d3a33bdbd"},{"ReferencingAttribute":"preferredequipmentid","ReferencedEntity":"设备","MetadataId":"b4b462b5-ee78-467d-a97a-45264d234816"},{"Referenc ing属性":"primarycontactid","ReferencedEntity":"联系人","MetadataId":"410707b1-9554-4cd9-8437-6608b1802904"},{"ReferencingAttribute":"masterid","ReferencedEntity":"帐户","MetadataId ":"51fa4af7-93d0-4f06-8949-38a0036ddc64"},{"ReferencingAttribute":"preferredsystemuserid","ReferencedEntity":"systemuser","MetadataId":"a6b48e23-fada-4b7f-8655-530bba050765"},{ "ReferencingAttribute":"createdbyexternalparty","ReferencedEntity":"externalparty","MetadataId":"9967fe7d-84ee-4a26-9ad7-a8fdbdfa2316"},{"ReferencingAttribute":"修改者","ReferencedEntity":"systemuser", "MetadataId":"8be02a9d-0776-4c76-b35f-1c92dd791d9e"},{"ReferencingAttribute":"parentaccountid","ReferencedEntity":"帐户","MetadataId":"57511732-b553-4cfb-bcf2-d280f9f8c6f1"} ,{"ReferencingAttribute":"entityimageid","ReferencedEntity":"imagedescriptor","MetadataId":"5b4942d5-1fcd-49ca-91c0-2737f5f104f3"},
另外,作为参考,我尝试$expand对属性和目标进行操作:
../api/data/v9.1/EntityDefinitions(LogicalName='account')?$select=LogicalName&$expand=Attributes($filter=AttributeType+eq+Microsoft.Dynamics.CRM.AttributeTypeCode%27Lookup%27&$expand=Targets)
它抛出一个错误:
“查询选项‘$expand’被指定多次,但最多只能指定一次。”
| 归档时间: |
|
| 查看次数: |
4587 次 |
| 最近记录: |