I'm trying to create some fetch xml or a query expression for CRM 2011.
I would like to OR the two linked entity nodes below. Is this possible at all, I need to do it in one request.
If I can perform this query I intend to modify the Activity History RetrieveMultiple views events by injecting extra criteria, similar to below.
<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>
Here's the SQL that brings back the results I'm looking for, please note that the issue issue is recreating the fetchXml for the where clause, specifically checking that one of the joins exist.
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
Please help.