One of the new features introduced with Update Rollup 5 for CRM 2011 was the introduction of activity feeds to CRM. Activity Feeds give users the ability to monitor what is happening to various business entities. The out of the box functionality includes auto posts that include activities such as status changes in business entities, and manual posts that are created by users. Users also have the ability to post comments to posts that are created in an activity feed. Recently, I had the need to retrieve activity feeds for various business entities in order to display a summary of interactions that had recently taken place for a set of accounts and its related entities. While the out of the box functionality allows a user to see the record wall for an individual record, it does not give the user the ability to see activity posts for multiple records on a single wall, hence the need to retrieve the posts using the OrganizationService.
The OrganizationService provides two messages for retrieving activity posts. These are the RetrieveRecordWallRequest and RetrievePersonalWallRequest. These messages do exactly what you would think. The RetrieveRecordWallRequest retrieves all of the posts that involve the specified record in CRM, while the RetrievePersonalWallRequest retrieves all of the posts for a user that they are following or in which the user is mentioned. Let’s explore these two messages in a little more detail so that we can use the data that they expose.
In order to retrieve posts to a record wall we will use the RetrieveRecordWallRequest. The following shows an example of the service call.
As you can see, in this request to the service we created an instance of the RetrieveRecordWallRequest and passed it to the Execute method of the OrganizationService. Notice in line 3 that we specified 50 for the number of CommentsPerPost and in line 6 we also specified the PageSize as 100. Both of these are the maximum allowed values when making a request for wall posts. This will return up to 100 posts for the record and up to 50 comments for each post. If more posts are desired, another request can be made with the PageNumber property of the request changed to specify a different page. Also, notice that for the record wall request that we had to specify an entity reference to the record for which we wanted posts as done in line 4.
The other request for posts that can be made is for personal wall posts. This is done using the RetrievePersonalWallRequest message. The following shows an example of the service call.
As you can see in this example, the request is a little simpler. In this case we still specified the CommentsPerPost, PageNumber, and PageSize, but we did not have to specify an entity reference. This is because the RetrievePersonalWallRequest will retrieve the post corresponding to the user in context that is making the service request. If we wanted to retrieve the wall for a different user we would have to impersonate the user for which we wanted posts when getting a reference to the OrganizationService used.
So now that we have the data, what does it look like? Well, both of the requests return a result that contains an EntityCollection property that is a collection of Post entities. Each of the post entities will also contain data for the comments if they exist in the RelatedEntities collection of the individual entities. The relationship to reference is the “Post_Comments” relationship. The following diagram gives more detail as to what data is exposed.
Probably the most important piece of data in the entities is the [text] attribute. This is the attribute that actually contains the text for the post or comment. The text in this field is already localized for the current user, but it does contain placeholders for other records that are referenced by the post. The format of the placeholder is [ObjectTypeCode,ID,”Display String”] for example, [1,00000000-0000-0000-0000-000000000000,”An example post or comment.”]. This placeholder will have to be replaced with the desired text if the post is going to be displayed for the end user.
Hopefully, this example will help you get the activity post data for your business requirements. If you need more information concerning activity feeds you can
Post by: Nick Doriot,