0

i've been breaking my head for days about this issue:

Imagine a custom retention formula that calculates an expiration date. The formula calculates the expiration date based on the creation date and another date field (AvailableUntil). If the 'other' date field has not been passed, the item cannot expire thus an expiration date cannot be set. To be complete, see my formula code but i'm sure everything works fine.

public DateTime? ComputeExpireDate(Microsoft.SharePoint.SPListItem item, System.Xml.XmlNode parametersData)
    {
        DateTime? expiracyDate = null;

        Logger l = new Logger(DiagnosticsCategory.Retention);
        l.Info("Calculating expiration date for messages - archive creation date + available until");

        RetentionRepository retentionRepository = new RetentionRepository(l, new Guid(Constants.RetentionModuleGUID), item.ParentList.ParentWeb.Site);

        RetentionPolicy policy = null;

        SPSecurity.RunWithElevatedPrivileges(delegate
        {
            policy = retentionRepository.GetPolicy(new Guid(Constants.RetentionModuleGUID));
        });

        if (policy != null)
        {
            DateTime createDate = SPUtility.ParseDate(item.ParentList.ParentWeb, item[SPBuiltInFieldId.Created].ToString(), SPDateFormat.DateTime, false);
            DateTime? availableUntilDate = null;

            try
            {
                availableUntilDate = SPUtility.ParseDate(item.ParentList.ParentWeb, item[CoreConstants.Constants.AvailableUntil_FieldInternalName].ToString(), SPDateFormat.DateTime, false);
            }
            catch (Exception ex)
            {
                l.Error(ex.Message);
            }

            if (policy.ArchiveDays > 0)
            {
                expiracyDate = createDate.AddDays(policy.ArchiveDays);
            }

            if (policy.ArchiveMonths > 0)
            {
                expiracyDate = createDate.AddMonths(policy.ArchiveMonths);
            }

            if (policy.ArchiveYears > 0)
            {
                expiracyDate = createDate.AddYears(policy.ArchiveYears);
            }

            if ((availableUntilDate != null && availableUntilDate > DateTime.Now) || (expiracyDate != null && expiracyDate > DateTime.Now))
            {
                // Available until date is not yet passed, no retention!
                // Never set an expiracy date in the future
                expiracyDate = null;
            }

            l.Info("Calculated expiracy date: " + expiracyDate.ToString());
        }
        else
        {
            l.Error("Could not retrieve the policy for " + Constants.RetentionModuleName);
        }

        return expiracyDate;
    }

The policy has been added on the content types on a list.

Now what happens:

  • I add an item to the list: the expiration date is calculated (whether it returns a date or null, it's done its job).
  • Now imagine i modify the item, to be more specific the AvailableUntil date field.

I would assume that modifying the original item, would re-calculate the expiration date the next time my 'information management policy' timer job runs. That seems not to be the case.

Can anyone assist me on how i can force a re-calculation of the expiration date? Am I the only one that doesn't find this normal behaviour. The expiration date is calculated once and once only.

The only way i could re-calculate the expiration date is to re-apply the policy on the list content type but that seems to be a bit overload in our scripts.

We thought that returning 'null' in the ComputeExpireDate method would set the item's retention date to null. We then reasoned that SharePoint would re-calculate until a date is set as expiration. Not the case apparantly.

Can anyone shed a light on this? I would be very grateful!

0

It seems that the problems came from updating the item's fields with powershell. If i update an item with powershell (to set the create date earlier to test the retention), the _dlc_ExpireDate is cleared but not 'marked' to set as recalculate.

If we edit an item through the web, it seems an event receiver is recalculating the expiration date on the fly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.