Tuesday, November 18, 2008

Understanding Record Management Feature Part 4 –Expiration Policy

Hi All,

You can read other articles of the series.

Understanding Record Management Feature Part 1 - Document Information Panel

Understanding Record Management Feature Part 2 - Labeling

Understanding Record Management Feature Part 3 - Barcode

Understanding Record Management Feature Part 5 – Auditing

Let’s continue with our record management feature. This time we will take up one very important feature in record management and that is expiration policy.

Name itself suggest that expiration policy means something related to define a rule when to expire the item. Yes it is all about the same. Here we can define the policy that when the particular item needs to expire and what steps to be taken when that item is expired.

Record managers have to define this policy and have to define the steps to be carries out what to do. All these actions can be customized. When I say customized means developers can also help defining the policies and custom action plan to execute based on this expiration policies.

Out of the box policies and out of the box way to define the expiry date of the item and actions to be taken is very simple step to configure. The other way to work with this is define expiration of the item programmatically.

To make you more understand, as we have used the metadata columns in the label, in the same way we can use the metadata columns of our document library to define the expiration policy. It works on date columns defined in your document library. If you observe if you do not have any date columns, then it will give you two options. One is created and other one is modified because these columns are already there in each list and library. If you have defined any other date column, it will appear there also. In my case I have defined one column which is “To Be Reviewed” and it is of type date. So I can have that column available to set the expiration policy and in this example I will use it.

The other way as I have mentioned is to set this expiration policy programmatically. Here in this article we are going to take both of them one by one.

Ok, let’s go ahead and start the practical example.

Step 1: open your document library. I am going to use my document library which I used in my previous three articles of the same series. Go to Document Library Settings -> Information management policy settings->Define Policy.

Step 2: Check Enable Expiration and it will give you an option to set some parameters.



Step 3: Select time period based on the item's properties and select your date column. I am selecting To Be Reviewed column and I want the item to expire after 2 days of it. I also want that this item is to be deleted after expiry so I select Delete option from performs this action drop down as well.



Step 4: Press OK and you are good to test this. Go back to document library and create one document. As I have my column as one of the properties in it, I’ll set it and based on that we will move ahead. Create a document and save it. Let me demonstrate you the date as well. If today is 14th November, and I set To Be Reviewed date is also 14th November then that means the document should be no longer there on 17th November.



See, I have set the To Be Reviewed Date to 14th of November.



Now to test this we have two ways. Ok so let’s wait for two days as today is Friday and weekend will be holiday for me, so I would like to continue with this on Monday because by Monday document will be no more available in the document library and I can continue with the same article and same post.

Ok, it’s Monday for me now, and it’s time to take a look at the document library, and yes it was what I expected. It should expire and it got expired.



Let’s take other approach. Let’s set the expiration policy programmatically. First you may need to include C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Policy.dll for this.

SPContext.Current.Web.AllowUnsafeUpdates = true;

SPListItem objItem = null;

SPDocumentLibrary objDocLib =
(SPDocumentLibrary)SPContext.Current.Web.Lists["Projects Documents"];

for (int iCnt = 0; iCnt <= objDocLib.Items.Count - 1; iCnt++)
{
objItem = objDocLib.Items[iCnt];

bool isExpirySet = Expiration.SetExpirationDateForItem(objItem, DateTime.Now.AddDays(2), false);

objItem.Update();

}

SPContext.Current.Web.AllowUnsafeUpdates = false;



Here what we did is we loop through each documents and set their expiration days to 2 days.

If you want to use your own column to set the expiration policy then I would suggest when you add the item in document library capture its adding event and there fetch that date, as I have To Be Reviewed date, I will fetch this column value in event handler and then use that column instead of directly using DateTime Class.

Other important thing to note is that expiration actions actually take place once a day not at the same moment when item expires. To check this open central administration, Go to operations-> Under Security Configuration->Management information policy configuration. As you click on this, you get idea about all four policies been controlled here. Go to Expiration for right now. Click on expiration. Here take a look at settings. It says that expiration actions take place at certain time not immediately. Here you can change you timings for schedule expiration.



You can click on process expired items now. Once you click on that, you get clear picture that it is actually a timer job that runs and performs the action.



You have to achieve two things. One is to set the expiration from code which we had done from code and the other one is to trigger the workflow when item expires.
To achieve the other one, we will take up the following approach. Create one event handler; register it with your document library. Event handler will be ideally ItemDeleting. There you trigger the workflow from code and workflow will be invoked and you can access the Item with the workflow properties as usual. That solves your problem. to learn how to start workflow programmatically, click here

That's it. i will continue this series with next article as well.

4 comments:

Unknown said...

I have been experimenting with the Information Management Policy settings and the Expiration Job Timer. My primary interest is to launch an expiration workflow on a library daily that does a check for an expiration date that I calculate based on a custom date column I call Reviewed date. All works well the first time the expiration date is reached but once the expiration worfklow runs, it doesnt appear it will run on the same file again even if a new expiration date is specified for it in properties. If I run the workflow manually it works, however the Expiration timer does not seem to run the workflow against the file.

SharePoint Kings said...

David,

your problem looks genuine, but it looks like Expiration Policy will implied that if a document expired then it should not be modified. that's why its not starting your workflow.

this is what we are thinking. let us find more when we get time and will let you know.

Chandresh said...

Hi,

I am also facing same problem , i searched more on it but i can not find any solution.

Please let me knw, if you have solution on same.


Thanks,
Chandresh

Bindu said...

Hi,
I want to know abt Announcement Expiration policy in sharepoint 2010.
Please help me regarding this.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com