views:

435

answers:

1

I’ve got some concerns with an approach I’m taking to centralize a calendar in MOSS. The scenario is that there is 1 calendar for the Enterprise and Events are filtered via audience targeting. It’s fairly straight forward to turn audience targeting on in a calendar, my concern comes when the client wants to auto populate that event with a default value in Target Audiences.

For example if a store manager is posting the event the target audience would only be the store, likewise if a district manager posts an event it would only apply to the stores in his/her district. The idea is to pull a default group from AD or even Global Audiences if needed, to “default” the Target Audience based on who is creating the event.

I'm guessing I'll need to use the AudienceManager class and an event handler to get this accomplished.

Can I set the Target Audience via JQuery to an AD Group? Do I need to override an Event Handler like ItemAdding to go and retrieve the group?

This seems like it would be a pretty common request when utilizing Target Audiences with a calendar event but I've spent quite of bit of time trying to find examples and have come up short.

A: 

My best guess is that you should indeed use an ItemEventReceiver, overriding the ItemAdding and ItemUpdating event (incase the item is edited?), both calling the same method SetAudience, in that method you set the audience based on SPCOntext.Current.Web.CurrentUser and the groups he is in, or perhaps some custom permission level you create

Incomplete code:

protected override ItemAdding(properties)
{
  SetAudience(properties.ListItem)
}

protected override ItemUpdating(properties)
{
  SetAudience(properties.ListItem)
}

private void SetAudience(SPListItem item)
{
  // get current user's groups
  // check if user is a member of store managers / district managers group
  // get all audiences below this user (i.e. all stores in district or single store
  // add relevant audiences to item
}

}

Colin