Welcome to TechNet Blogs Sign in | Join | Help

Creating Audience Rules via the Object Model

SharePoint Server (MOSS) was designed as a platform for building applications upon. Using the SharePoint Server Object Model (OM) exposes many different and often more complicated operations than what can be done with the UI only.

An example of this is with Audience creation. Audiences are an organizational type concept that is associated with the Shared Service Provider (SSP). Audiences can be built up using rules that are exposed within the Admin UI for such properties as Account Name or Title. In this way you may be able to create audiences that comprise of user profiles that all have a property in common and can then use this compiled audience for such things as targeting content.

The Audience OM allows the creation of audiences that can be more complicated in their evaluation. For example, the Audience OM allows the groupings of audience rules which will result in compiled audiences based on a combination of AND/OR clauses.

                // Create thet test audience.
                this.testAudience  = this.audienceManager.Audiences.Create(
                    TestStringGenerator.GetString(MaxAudienceNameLength),
                    TestStringGenerator.GetString(
                        MaxAudienceDescriptionLength));
                this.testAudience.GroupOperation =
                    AudienceGroupOperation.AUDIENCE_OR_OPERATION;

                // Add the desired rule to the test audience.
                ArrayList audienceRules = new ArrayList();

                AudienceRuleComponent r1 = new AudienceRuleComponent("AccountName", "Contains", this.DLTestAccountName1);
                audienceRules.Add(r1);

                AudienceRuleComponent r2 = new AudienceRuleComponent(null, "OR", null);
                audienceRules.Add(r2);

                AudienceRuleComponent r3 = new AudienceRuleComponent("AccountName", "Contains", this.DLTestAccountName2);
                audienceRules.Add(r3);

                this.testAudience.AudienceRules = audienceRules;
                this.testAudience.Commit(); 

 

From the code above you can see that:

this.testAudience.GroupOperation =
                    AudienceGroupOperation.AUDIENCE_OR_OPERATION;

Sets the group operation for the audience similar to the Audience Admin UI where you can select

 

 

But with via OM you can specify groupings by using parentheses () with this:

new AudienceRuleComponent(null, "(", null);

<some audience rules>

new AudienceRuleComponent(null, ")", null);

so that now you can represent an expression like this:

(AccountName contains DLTestAccountName1 OR AccountName contains DLTestAccountName1)

AND

(Title contains TestTitle1 OR Title contains TestTitle2)

Published Wednesday, October 03, 2007 3:04 PM by chrishe

Comments

Tuesday, December 18, 2007 6:26 PM by stevensux

# re: Creating Audience Rules via the Object Model

Is there a trick to creating rules (programmatically) that involve membership in a domain group? When i try this the audience is created with the rules I specify but they all say "Non-existent Membership group" even though the group exists.

Tuesday, December 18, 2007 7:42 PM by chrishe

# re: Creating Audience Rules via the Object Model

Are you trying with something like this:

AudienceRuleComponent r1 = new AudienceRuleComponent("DL", "Member of", "Domain\GroupName");

If so then yes, there is a bit of a trick since you will need to get the distinguished name of the group in question. You can get the DN either programmatically (sorry I don't have sample code in front of me) or using a tool like ADSI Edit).

Anonymous comments are disabled
 
Page view tracker