How to pass parameters/config data into custom Expiration formula

When developing a custom Expiration formula in SharePoint you may want to pass in parameters/config data for the formula, e.g. only expire items where field X has value Y.

The method that you needs to implement for your formula has the below signature:

public DateTime? ComputeExpireDate(SPListItem item, XmlNode parametersData)
{ }

You can pass params/config data to your formula via the parametersData parameter. This is a piece of XML that will have the following schema:

<formula id="[the ID you assigned to your custom formula]">
    <!--Your custom XML, e.g. the below -->

You can set the XML contained within parametersData when you enable the Expiration policy feature for a policy using code. The code below for example enables the Expiration policy feature for a content type. The code configures the Expiration policy feature to use a custom Expiration formula, and pass in XML to be used inside that formula (via parametersData).

//Needs using Microsoft.Office.RecordsManagement.InformationPolicy;

public void EnableExpirationForContentType(SPContentType contentType)
            const string EXPIRATION_POLICY_FEATURE_ID = "Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration";

            //Ensure that a policy is defined for the content type
            Policy policy = Policy.GetPolicy(contentType);
            if (policy == null)
                Policy.CreatePolicy(contentType, null);
                policy = Policy.GetPolicy(contentType);

            //Always overwrite any existing Expiration setting for the policy (i.e. delete if exists)
            if (policy.Items[EXPIRATION_POLICY_FEATURE_ID] != null)

            //The id attribute must points to an Expiration formula you have deployed to the server
            string policyFeatureXml =
    <formula id=”"MyCustomExpirationFormula”">
        <!—From here on is your custom XML—>
    <action type="workflow" id="[guid of a workflow that has been associated with the content type]" />

            //Enable the Expiration policy feature
            policy.Items.Add(EXPIRATION_POLICY_FEATURE_ID, policyFeatureXml);

Note the id attribute in the XML must point to an Expiration formula you have deployed to the server. Follow this tutorial for how to develop, deploy and debug a custom Expiration formula:


About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Information Management Policy, SharePoint. Bookmark the permalink.

2 Responses to How to pass parameters/config data into custom Expiration formula

  1. Daniel Moore says:

    Great post! Thank you very much for covering this. From where do the parameters get passed? From the admin GUI where you set the Expiration policy?

    • Bernado says:

      Hey Daniel, OOTB there is no GUI to define parameters for your custom Expiration formula. The only way (that I know of) to define parameters and pass in values for them is in your custom code, as shown in this post. You should consider carefully when using this approach. This is because if a user edit the Information Management Policy through the OOTB GUI, then your custom parameters and their values will be overwritten by the GUI – hence lost.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s