The Microsoft Dynamics CRM Blog
News and views from the Microsoft Dynamics CRM Team

Like-Unlike for Activity Feeds

Like-Unlike for Activity Feeds

  • Comments 0

 

Activity Feeds solution has been on the marketplace since late last year. With an upcoming UR, we are
adding new cool features including filters, ability to set a default view and
of course like-unlike. In this post we’ll walk through the like-unlike feature
and SDK how-to.

If you’d like a quick refresher on the SDK, try this
post. There is also sample code up on MSDN.

Social networks have set somewhat of a standard to quantify
the popularity of posts. Facebook has the like button, Google+ uses +1. This
system encourages users to participate actively as well get a feel of the
response to content that they have created. Overall, it gives the feeling of
being part of a community. Expressing this is quick, usually with the click on
a single button and feedback is represented along with the content of the post
itself.

Like-Unlike inches the social experience in CRM closer to
what users are already familiar with through other networking services.
Hovering over a post typically shows at least one button, viz., Comment. Now,
you’ll see a new ‘Like’ button like so:

 

Clicking it likes a post and changes the button text to
‘Unlike’. The content below the post text now indicates that you’ve liked this
post:

When another user views this post on their wall, they see
something like this:

The like count obviously reflects the number of people that
like it. Clicking the number displays the names of people who like this post in
a popover:

The Windows
Phone app has this ability too:

The smiley
icon in the left bottom corner likes a post.

 

Like-Unlike
works the same way whether you are on your personal wall, on an entity’s wall
on an entity form, even on read-only forms. A user can like-unlike all posts
irrespective of how they’ve been created- by other users, by workflows or rule
triggered auto-posts. A user will require the same permissions that they need
for Activity Feed post or comment creation.

 

There is SDK
support as well. The following code snippets show how you can like a Post and
retrieve user’s full names who like a particular post.

 

Like a post with a particular Id var postLike = new PostLike { PostId = new EntityReference(Post.EntityLogicalName, post.Id) };

Guid likeId = _serviceProxy.Create(postLike);

Console.WriteLine("Post with Id :{0} liked.", post.Id);

 

Retrieve list of likes for a particular post

string retrieveLikesFetchXml = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"true\" returntotalrecordcount='true'>" + 
                                   "<entity name=\"systemuser\">" +
                                   "<attribute name=\"fullname\"/>" +
                                   "<attribute name=\"systemuserid\"/>" + 
                                   "<order descending=\"false\" attribute=\"fullname\"/>" +
         "<link-entity name=\"postlike\" alias=\"aa\" to=\"systemuserid\" from=\"createdby\">" +
                                   "<filter type=\"and\">" +                   "<condition attribute=\"postid\" value=\"{" + post.Id +"}\" operator=\"eq\"/>" +
                                   "</filter>" + 
                                   "</link-entity>" + 
                                   "</entity>" +
                                   "</fetch>";

 

var fetchExpression = new FetchExpression(retrieveLikesFetchXml);

var likes = _serviceProxy.RetrieveMultiple(fetchExpression);

 

Console.WriteLine("{0} users like this post. They are:", likes.Entities.Count);

         foreach (var entity in likes.Entities)

         {

                 Console.WriteLine(entity.Attributes["fullname"]);

         }

 

 

Since the aim of Activity Feeds is to encourage communication, there is no way to
‘dislike’ a post. For the same reason, you cannot like or unlike a post via
workflows.

 Aniket Naravanekar <anikna@microsoft.com>

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post