Item-Level Audience Targeting with GetListItems

Apr 19, 2012 at 1:14 PM

Has anyone had any success with item-level audience targeting using GetListItems or is using a CQWP the only way?

Apr 19, 2012 at 1:56 PM

Say more....

Apr 19, 2012 at 2:34 PM

Say you have an out of the box announcements list with target audiences enabled.  Out of the box, if you want to display those announcements on a web part page, you can add a Content Query Web Part and have it filter by audience so only members of that audience can see a particular announcement.  I'm curious if the same functionality can be used with an SPServices' GetListItems call.

Thanks.

Apr 19, 2012 at 2:47 PM

I checked out the out-of-the box Anouncements list and I don't see how you would target audience... so you must be perhaps adding an additional column of type GROUP and maybe using it to define, for each row, what group the announcement is meant for... is that your use case? I'm just trying to understand how your data is defined to see what I can suggest.

CQWP audience targeting (I think) works by defining the list of people/groups the webpart should be displayed to... If you have that same data available for each row in your "announcements" list, then yes, with some client side JS code and the help of SPServices, I belive you can implement similar functionality.

Paul.

Apr 19, 2012 at 3:26 PM

Hi Paul,

To enable Audience Targeting out-of-the-box in SharePoint 2010, you would go to List Settings, click on Audience Targeting settings, and check Enable audience targeting.  This will create a column of type Audience Targeting - it's a default engine SharePoint uses for this functionality that will filter list items by audience in a CQWP (and can also be set to display non-targeted content if required).  

It's easy enough to do it by webpart (and even create multiple webparts off the same announcements list targeted specifically to each audience), but like the CQWP, the business use is for targeting at the item-level without multiple web parts given that there are more than 50 audiences used within this context, and not all content is targeted.  It would be ideal if I could access that audience targeting engine in SharePoint with SPServices.

Thanks,

Gabe

Apr 19, 2012 at 3:59 PM

Got it now... Thanks...

I see that column created (Target_x0020_Audiences) and can get it to return on the response, but for some reason I can't figure a way to query it... CAML API has 'Membership' element (http://msdn.microsoft.com/en-us/library/aa544234.aspx) that can be worked into a Query, which looked promising, but on a quick test, I was not able to make it work... perhaps you can figure a way to do it (and post back so others can benefit as well :) ) The example on the MS page is:

<Or>
  <Membership Type="CurrentUserGroups">
    <FieldRef Name="AssignedTo"/>
  </Membership>
  <Eq>
    <FieldRef Name="AssignedTo"></FieldRef>
    <Value Type="Integer">
      <UserID/>
    </Value>
  </Eq>
</Or>

Paul

May 14, 2012 at 5:10 PM

To anyone who may be looking to enable this with SPServices, I was not able to get this to work (doesn't mean it's impossible, only that I could not). 

For my scenario, I opened up Visual Studio and had success in using the CrossListQueryInfo class (http://msdn.microsoft.com/en-us/library/ms561846) to create a customized control with audience filtering enabled.  In hindsight (and good learning for requirements gathering for future projects), unless you absolutely must have customizations here, I would recommend sticking with the out-of-the-box CQWP for this functionality if you can help it. 

Gabe