Table of Contents

Codeunit "Apply Retention Policy"

ID 3910
Namespace: System.DataAdministration

This codeunit provides functions to apply a retention policy.

Properties

Name Value
Access Public

Methods

ApplyRetentionPolicy

Applies all enabled, non-manual retention polices. This will delete records according to the settings defined in the Retention Policy Setup table.

procedure ApplyRetentionPolicy(UserInvokedRun: Boolean)

Parameters

Name Type Description
UserInvokedRun Boolean

Use this value to indicate whether the user initiated the function call or an automated process did. This value is later passed in the event OnApplyRetentionPolicyRecordLimitExceeded.

ApplyRetentionPolicy

Applies the given Retention Policy. This will delete records according to the settings defined in the Retention Policy Setup table.

procedure ApplyRetentionPolicy(RetentionPolicySetup: Record "Retention Policy Setup", UserInvokedRun: Boolean)

Parameters

Name Type Description
RetentionPolicySetup Table System.DataAdministration."Retention Policy Setup"

This is the setup record which defines the retention policy to apply.

UserInvokedRun Boolean

Use this value to indicate whether the user initiated the functioncall or an automated process did. This value is later passed in the event OnApplyRetentionPolicyRecordLimitExceeded.

GetExpiredRecordCount

Returns the number of expired records for the given Retention Policy Setup record. These records would be deleted if the Retention Policy was applied.

procedure GetExpiredRecordCount(RetentionPolicySetup: Record "Retention Policy Setup"): Integer

Parameters

Name Type Description
RetentionPolicySetup Table System.DataAdministration."Retention Policy Setup"

This is the setup record which defines the retention policy for which the expired records will be counted.

Returns

Type Description
Integer

The number of records which are expired.

GetExpiredRecordCount

Returns the number of expired records for the given Retention Policy Setup record. These records would be deleted if the Retention Policy was applied.

procedure GetExpiredRecordCount(RetentionPolicySetup: Record "Retention Policy Setup", var ExpiredRecordExpirationDate: Date): Integer

Parameters

Name Type Description
RetentionPolicySetup Table System.DataAdministration."Retention Policy Setup"

This is the setup record which defines the retention policy for which the expired records will be counted.

ExpiredRecordExpirationDate Date

The earliest expiration date for which there are more expired records than the maximum to be deleted in a single run.

Returns

Type Description
Integer

The number of records which are expired.

SetWhereOlderExpirationDateFilter

This method places a filter on the record reference where records are older than the ExpirationDate. The filter excludes any record where the date field specified in DateFieldNo has no value.

procedure SetWhereOlderExpirationDateFilter(DateFieldNo: Integer, ExpirationDate: Date, var RecordRef: RecordRef, FilterGroup: Integer, NullDateReplacementValue: Date)

Parameters

Name Type Description
DateFieldNo Integer

The date or datetime field the filter will be placed on.

ExpirationDate Date

The expiration date used in the filter.

RecordRef RecordRef

The record reference on which the filter will be placed.

FilterGroup Integer

The filtergroup in which the filter will be placed.

NullDateReplacementValue Date

The date to be used to determine whether a record has expired when the date or datetime value of the record is 0D.

SetWhereNewerExpirationDateFilter

This method places a filter on the record reference where records are newer than the ExpirationDate. The filter excludes any record where the date field specified in DateFieldNo has no value.

procedure SetWhereNewerExpirationDateFilter(DateFieldNo: Integer, ExpirationDate: Date, var RecordRef: RecordRef, FilterGroup: Integer, NullDateReplacementValue: Date)

Parameters

Name Type Description
DateFieldNo Integer

The date or datetime field the filter will be placed on.

ExpirationDate Date

The expiration date used in the filter.

RecordRef RecordRef

The record reference on whic the filter will be placed.

FilterGroup Integer

The filtergroup in which the filter will be placed.

NullDateReplacementValue Date

The date to be used to determine whether a record has expired when the date or datetime value of the record is 0D.

SetSingleDateExpirationDateFilter

This method places a filter on the record reference where records are expired one day at the expiration date. The filter excludes any record where the date field specified in DateFieldNo has no value.

procedure SetSingleDateExpirationDateFilter(DateFieldNo: Integer, ExpirationDate: Date, var RecordRef: RecordRef, FilterGroup: Integer, NullDateReplacementValue: Date)

Parameters

Name Type Description
DateFieldNo Integer

The date or datetime field the filter will be placed on.

ExpirationDate Date

The expiration date used in the filter.

RecordRef RecordRef

The record reference on whic the filter will be placed.

FilterGroup Integer

The filtergroup in which the filter will be placed.

NullDateReplacementValue Date

The date to be used to determine whether a record has expired when the date or datetime value of the record is 0D.

Events

OnApplyRetentionPolicyRecordLimitExceeded

This event is raised once the maximum number of records which can be deleted in a single run is reached. The limit is defined internally and cannot be changed. The event can be used to schedule a new run to delete the remaining records.

[IntegrationEvent(False,False)]
internal procedure OnApplyRetentionPolicyRecordLimitExceeded(CurrTableId: Integer, NumberOfRecordsRemainingToBeDeleted: Integer, ApplyAllRetentionPolicies: Boolean, UserInvokedRun: Boolean, var Handled: Boolean)

Parameters

Name Type Description
CurrTableId Integer

Specifies the Id of the table on which the limit was reached.

NumberOfRecordsRemainingToBeDeleted Integer

Show the number of records remaining to be deleted for the table specified in CurrTableId.

ApplyAllRetentionPolicies Boolean

Specifies where the interupted run was for all retention policies or only one retention policy.

UserInvokedRun Boolean

Specifies whether the run was initiated by a user or not.

Handled Boolean

Specifies the Id of the table on which the limit was reached.

OnApplyRetentionPolicyIndirectPermissionRequired

This event is raised when the user applying the retention policy has indirect permissions to delete records in the table. A subscriber to this event with indirect permissions can delete the records on behalf of the user.

[IntegrationEvent(False,False)]
internal procedure OnApplyRetentionPolicyIndirectPermissionRequired(var RecRef: RecordRef, var Handled: Boolean)

Parameters

Name Type Description
RecRef RecordRef

The record reference which contains the expired records to be deleted.

Handled Boolean

Indicates whether the event has been handled.

See also