Loading...

Last updated: Dec 10 2018

Area: Episerver Add-ons Applies to versions: 4.20.0 and higher

Customizing retention policies

Editors can set a retention policy in the user interface, that is, control how long finalized form submissions and partially submitted form data should be stored. This topic describes how to change the date for a specific submission and how to change the default values through code.

In this topic

Use Actor to change expired date of submission

By default, the retention policy of a form applies to all its submissions. It is possible to write a custom actor to change the date for a specific submission. In this example, we create a custom actor to check if a submission comes from an internal or external visitor. If it comes from an internal user, the expired date is set to the previous day so the submission is deleted right after  the Submission Cleanup scheduled job is run.

  1. Create a class that implements the PostSubmissionActorBase and ISyncOrderedSubmissionActor classes.
  2. Implement the new class as below:
    public class CheckInternalSubmissionActor : PostSubmissionActorBase, ISyncOrderedSubmissionActor
    {
    public int Order => 500;
    public override object Run(object input)
    {
    //get client ip
    var geoDataSource = new GeoVisitorDataSource();
    var geoData = geoDataSource.GetGeoDataAsync().Result;
    //get local ip address
    var localIPList = new List<string>() { "192.168.1.1" };
    //check if submission comes from internal address, if yes then set expired date to previous day
    if (localIPList.Contains(geoData.ip)){
    var item = SubmissionData;
    item.Data[Constants.SYSTEMCOLUMN_ExpiredDate] = DateTime.UtcNow.AddDays(-1);
    }
    
    return null;
    }
    }​

Note: ExpiredDate should be stored as UTC time format, otherwise it may cause some unexpected issues.

Change default value of retention policies

Episerver Forms uses SubmissionRetentionService to get the default value for the retention periods of partial and finalized submissions. You can inherit that class and override the method to get a custom default value for the retention periods for submissions. Example:

[ServiceConfiguration(typeof(SubmissionRetentionService))]public class CustomSubmissionRetentionService : SubmissionRetentionService
{
/// <summary>
/// Get default retention period.
/// <returns>
/// A tuple contains 2 items:
/// Item1: Default retention period (days) value of partial submission.
/// Item2: Default retention period (days) value of finalized submission.
/// </returns>
/// </summary>
public override Tuple<int, int> GetDefaultRetentionPeriod()
{
return Tuple.Create(20, 60);
}
}

Then you need to go to DependencyResolverInitialization to register that service:

public void ConfigureContainer(ServiceConfigurationContext context)
{
//Implementations for custom interfaces can be registered here.
context.ConfigurationComplete += (o, e) =>
{
//Register custom implementations that should be used in favour of the default implementations
context.Services.AddTransient<IContentRenderer, ErrorHandlingContentRenderer>() .AddTransient<ContentAreaRenderer, AlloyContentAreaRenderer>()
.AddTransient<SubmissionRetentionService, CustomSubmissionRetentionService>(); 
};
}

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/