Creating content rules via Feature activation

The wonderful world of content routing is really limitless (well almost).

After turning the entire system almost inside out a new feature was added to the
scope. All the content rules are the same in the sub sites so every time a new sub
site is being created, all the content rules need to be created manually,
needless to say that this takes quite some time if you have a lot of content
types where the rules need to be set-up for.

So of course the question (well it was more of a suggestion from us) was, if we
couldn’t automate this process?

Let’s analyze it:

We have a list that cannot be found via the “view all content” link, euhm, ok but it’s
still a list. So via the spweb object it shouldn’t be a problem to find it.
Next, adding items is easy, but we still need to map the value to the fields of the listitem:

 

Internal Name

Display Name

Standard Value

Type

RoutingEnabled

Active

 

Yes
/ No

RoutingAliases

Aliases

 

Single
line of text

RoutingCustomRouter

Custom
Router

 

Single
line of text

RoutingRuleDescription

Description

 

Single
line of text

RoutingPriority

Priority

 

Single
line of text

RoutingConditionProperties

Properties
used in Conditions

 

Multiple
lines of text

RoutingAutoFolderProp

Property
for Automatic Folder Creation

 

Single
line of text

Route To External Location

Route
To External Location

 

Yes
/ No

ContentType

Content
Type

Rule

 

 

So now you use this with a SPListItem object to add content routing rules via code. It’s
best to do it with feature activation (scope web) and an activation dependency
to Content Organizer feature.

Only problem is, the field routingconditionproperties is multiline,
so ok, no problem here.

Try setting a value to this field and after that do an edit item via the GUI. You’ll see
that your condition isn’t set. The SharePoint guys really did a disappearing
act on this one. If you set the condition and save the item, than you’ll see
only the field name of the condition, not a (is equal, contains, larger than, …) or the value that you’ve specified.

After doing a lot of reflecting (if you really want to get to know SharePoint, you must do
some reflecting on the Microsoft.SharePoint.dll J ), I only found
out that an xml structure is being made here.

It has the following structure:

                <Conditions>

                               <Condition ColumnName=”  condition=””  value=”” />

 </Conditions>

But what happens after the creation of this xml structure still eludes me .

Leave a Reply

Your email address will not be published. Required fields are marked *