views:

1218

answers:

4

I want to show targeted (filtered) content from a list to users. I already have a column in the list that basically has the Target Audience value. This field is a multi-choice column (checkbox input) which I prefer over the current input field for Targeted Audiences.

To get audience filtering to work I unfortunately need to have the Targeted Audience field filled out for every list item. My current plan is to use a simple SharePoint designer workflow to set the Targeted Audiences field based on my other field, but I'm wondering if there is a better way. Am I just looking at this wrong?

Note that I know audiences can also be used to hide/show web parts, but that is not something I am interested in.

A: 

Maybe use a webpart to display the content of the list and use Audiences on the webpart sounds a solution easier to manage...

salgo60
Are you saying to use a custom web part? That could certainly work, but not the answer I was hoping to hear. My hope is that I just don't understand audiences enough and there is some simple setting that I am missing.
Kirk Liemohn
I see Audiencies just to mark on object if it is visible or not. Combined with permission settings can narrow what is displayed to different user groups...I have asked in another topic of good implementations of a hiding and showing menuitems dependent on the status of an item/member of audiences
salgo60
+3  A: 

You could try and give this a whirl...

SPField audienceField = null;

try
{
    audienceField = list.Fields[Microsoft.SharePoint.Publishing.FieldId.AudienceTargeting]
}
catch
{}

if(audienceField != null)
{
try
{
    Audience siteAudience;
    ServerContext context = ServerContext.GetContext(site);
    AudienceManager audManager = new AudienceManager(context);
    foreach (SPListItem item in list.Items)
    {
      string audienceName = item["fakeAudienceField"]; //should be the audience name created in SSP
      siteAudience = audManager.GetAudience(audienceName);
      Guid id = siteAudience.AudienceID;
      item["Target Audiences"] = id.ToString()+";;;;";
      item.Update();
    }
}
catch
{}
Steve Ruiz
Thanks for the code - it may prove useful.
Kirk Liemohn
A: 

I do not believe Target Audiences can be set up as a calculated field, in which case your options are workflow or a list item event receiver.

To set the audience field value, you can use AudienceManager.GetAudienceIDsAsText; Gary Lapointe has a post with example usage.

dahlbyk
Thanks - this looks like the best choice available to me.
Kirk Liemohn
A: 

I have a workflow that sets the Target Audience feild of a list item to be ESG-R Admin; ESG-R [%lookupvalue%] so that list items show to the admin group, and to those in the same region as the person the list item refers to.

I planned to use this on several lists, but am still working up the functionality (I've only been playing with Sharepoint for two months). Currently the workflow does update the Target Audience field, but without a press of the 'check addresses' box does not really apply it. I'm still working on that part.

Elena