2

I'm retrieving like ratings from a list. That is working. But I want to know if the current user has liked an item. I've added the LikedBy column to my include list. Here is the code that is working:

var ctx = new SP.ClientContext(<site>);
var ratingsList = ctx.get_web().get_lists().getByTitle(<ratingListName>);
var camlQuery = new SP.CamlQuery();
var camlStr ="<View><Query><Where><In><FieldRef Name='RelatedItemID' /><Values>";

  for(var i = 0;i<itemIDs.length;i++){
    camlStr += "<Value Type='Number'>"+itemIDs[i]+"</Value>";   
  }

  camlStr += "</Values></In></Where></Query>";

  camlQuery.set_viewXml(camlStr);

  var collListItem = ratingsList.getItems(camlQuery);   
  ctx.load(ratingsList);
  ctx.load(collListItem, 'Include(ID,LikesCount,RelatedItemID,Title,LikedBy)');
.....

The problem is that the values returned by LikedBy are just the display name John Q. Public. I can compare that with the current user, but what if there are two users with that name?

So I'm trying to get the expanded user data that I've been able to get in other places with CAMLQueryOptions:

<ExpandUserField>True</ExpandUserField></View>

But that doesn't seem to work. I found this page which suggests in the QueryOptions section that rowlimit and includeattachments are the only options that work in CAML query. (It is written oddly so I'm not sure what it is saying about expanduser).

In the REST api there is an $expand and I'm wondering if there something similar to that?

Is there another way I can do this?

  • Oddly enough I am able to get expanded user information using SP Services. I thought SPS was just a wrapper for the existing javascript api so I'm a little confused how it can get it but direct code can't? – Rothrock Sep 3 '15 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.