CRM 2011: ActivityPointer and Custom Fields

Nathan Eccles, 25 January 2013

CRM 2011 has given us this wonderful means of accessing all Activity entities through a single pointer, called the ActivityPointer. Unfortunately this pointer contains only out-of-the-box fields which are generic enough across the various Activities to warrant being included. This means that if you have a custom field added on all (or many) Activities, you are not able to reference it when looking at the ActivityPointer.

In reporting this can pose some issues as now, instead of querying one convenient pointer, you have to look into each Activity separately, and this can become cluttered and tedious, and often the only reason you wish to access that custom field is for filtering purposes.

In the case of simply requiring access to the field for filtering purposes, there is a handy way in which this can done which both filters the Activities as you wish, and maintains the cleanness of using the ActivityPointer. This is achieved through doing joins to the individual Activity entities and then filtering based on the custom field.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="activitypointer">
    <attribute name="subject" />
    <attribute name="regardingobjectid" />
    <attribute name="scheduledstart" />
    <attribute name="scheduledend" />
    <attribute name="statecode" />
    <attribute name="activitytypecode" />
    <attribute name="description" />

    <
link-entity link-type="outer" name="appointment" from="activityid" to="activityid" alias="App">
      <attribute name="activityid" />
      <filter type="and">
        <condition attribute="mag_isimportant" operator="eq" value="true" />
      </filter> 
    </link-entity> 

    <
link-entity link-type="outer" name="email" from="activityid" to="activityid" alias="EMail">
      <attribute name="activityid" />
      <filter type="and">
        <condition attribute="mag_isimportant" operator="eq" value="true" />
      </filter> 
    </link-entity> 

    <
link-entity link-type="outer" name="phonecall" from="activityid" to="activityid" alias="Phone">
      <attribute name="activityid" />
      <filter type="and">
        <condition attribute="mag_isimportant" operator="eq" value="true" />
      </filter> 
    </link-entity> 

    <link-entity link-type="outer" name="task" from="activityid" to="activityid" alias="Task">
      <attribute name="activityid" />
      <filter type="and">
        <condition attribute="mag_isimportant" operator="eq" value="true" />
      </filter> 
    </link-entity> 

  </
entity>
</fetch> 

This will however also show up activities which you have no linked out to. To remedy this, a simple null check around the “activityid” (which was included in each of the linked entities) will remove results which do not meet the specified criteria. This can be implemented in the Group Visibility by adding the following code for “Show or hide based on an expression”: 

=ISNOTHING(Fields!App_activityid.Value)
AND ISNOTHING(Fields!EMail_activityid.Value)
AND ISNOTHING(Fields!Phone_activityid.Value)
AND ISNOTHING(Fields!Task_activityid.Value) 

This code allows for ActivityPointer fields to be used in a relatively simple manner without a significant amount of duplication being required. However if you wish to custom fields to the report there is an added level of complexity which I shall cover in a future blog.