我正在尝试为 CRM 2011 创建一些 fetch xml 或查询表达式。
我想 OR 下面的两个链接实体节点。这有可能吗,我需要在一个请求中完成。
如果我可以执行此查询,我打算通过注入额外的条件来修改 Activity History RetrieveMultiple 视图事件,类似于下面。
<fetch mapping='logical' distinct='true'>
<entity name='activitypointer'>
<attribute name='activitytypecode' />
<attribute name='subject' />
<attribute name='statecode' />
<attribute name='prioritycode' />
<attribute name='modifiedon' />
<attribute name='activityid' />
<attribute name='instancetypecode' />
<order attribute='modifiedon' descending='false' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='1' />
</filter>
<link-entity name='activityparty' from='activityid' to='activityid' alias='aa'>
<link-entity name='account' from='accountid' to='partyid' alias='ab'>
<filter type='or'>
<condition attribute='accountid' operator='eq' uiname='A new Trust' uitype='account' value='{756CE4E9-F6F0-E111-8948-000C297B9BDA}' />
</filter>
</link-entity>
</link-entity>
<link-entity name='connection' from='record2id' to='activityid' alias='ad'>
<link-entity name='account' from='accountid' to='record1id' alias='ae'>
<filter type='or'>
<condition attribute='accountid' operator='eq' uiname='A new Trust' uitype='account' value='{756CE4E9-F6F0-E111-8948-000C297B9BDA}' />
</filter>
</link-entity>
</link-entity>
</filter>
</entity>
</fetch>
这是返回我正在寻找的结果的 SQL,请注意问题是为 where 子句重新创建 fetchXml,特别是检查其中一个连接是否存在。
SELECT DISTINCT
ap.activitytypecode,
ap.[subject],
ap.statecode,
ap.prioritycode,
ap.modifiedon,
ap.activityid,
ap.instancetypecode
FROM
dbo.FilteredActivityPointer ap
--First Link
LEFT OUTER JOIN dbo.FilteredActivityParty party
ON ap.activityid = party.activityid
AND party.partyid = '756CE4E9-F6F0-E111-8948-000C297B9BDA'
--Second Link
LEFT OUTER JOIN dbo.FilteredConnection connection
ON ap.activityid = connection.record2id
AND connection.record1id = '756CE4E9-F6F0-E111-8948-000C297B9BDA'
WHERE
ap.statecode =1
AND (
NOT party.partyid IS NULL
OR NOT connection.record1id IS NULL
)
ORDER BY
ap.modifiedon
请帮忙。