Featured Post

Web API Requests Series

Web API Series:  Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows

11 January 2012

How to retrieve all the activities for a record

In this post I will show how to retrieve all the activities in which a record is related to as:
  1. BBC Recipient
  2. CC Recipient
  3. Customer Optional Attendee
  4. Organizer
  5. Owner
  6. Regarding
  7. Required attendee
  8. Resource
  9. Sender
  10. To Recipient
It is also possible, of course, to select only few of them. To achieve this I will use a fetch XML query.
Here is  the query:

<fetch version="1.0" output-format="xml-platform" 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" />
    <link-entity name="activityparty" from="activityid" to="activityid" alias="aa">
      <filter type="and">
        <condition attribute="participationtypemask" operator="in">
          <value>4</value>
          <value>3</value>
          <value>11</value>
          <value>6</value>
          <value>7</value>
          <value>9</value>
          <value>8</value>
          <value>5</value>
          <value>10</value>
          <value>1</value>
          <value>2</value>
        </condition>
        <condition attribute="partyid" operator="eq" uitype="contact" value="Xrm.Page.data.entity.getId()" />
      </filter>
    </link-entity>
  </entity>
</fetch>

The corresponding advanced find query is:









Hope this helps,

Luciano.