DataMigrate Pro·Listener and extensions
DataMigrate Pro Subscriber: Truncate Extension Hook
The subscriber for OnAfterTruncateFailed lets extensions clean up their own tables when the truncate in DataMigrate Pro fails.
Purpose
DataMigrate Pro exposes an integration event when the built-in truncate attempt fails. This allows other extensions to handle table cleanup for their own tables, including tables that are not part of the current DataMigrate Pro permission list.
Typical use case:
- Your extension owns a table.
- The table requires direct delete permissions for truncate.
- DataMigrate Pro cannot declare permissions for your extension objects.
- Your extension subscribes to the event and performs cleanup with its own permissions.
Event Overview
Publisher object:
- Page
72359583 "BC Table List IOI"
Event name:
OnAfterTruncateFailed
Event signature:
[IntegrationEvent(false, false)]
local procedure OnAfterTruncateFailed(
TableNo: Integer;
TableName: Text[100];
var RecRef: RecordRef;
var Reseeded: Boolean;
var IsHandled: Boolean)
begin
end;When this event is raised:
- DataMigrate Pro already tried
RecRef.Truncate(true)and it failed. - Subscribers can try custom handling.
- If no subscriber handles it, DataMigrate Pro falls back to
RecRef.DeleteAll(true).
Contract for Subscribers
Use these parameters as follows:
TableNo: Selected table ID.TableName: Selected table name.RecRef: OpenRecordRefto the selected table.Reseeded:- Set to
trueif your handler completed a truncate with reseed behavior. - Set to
falseif your handler deleted rows without reseed.
- Set to
IsHandled:- Set to
trueif your subscriber performed the operation and DataMigrate Pro should stop default fallback handling. - Keep
falseif you do not handle the table.
- Set to
Important:
- Only set
IsHandled := truewhen your operation has actually succeeded. - Keep your logic table-specific to avoid accidental handling of unrelated tables.
Example Subscriber (Own Extension)
namespace MyCompany.MyExtension;
using IOI.DataMigratePro;
codeunit 70000010 "DMP Truncate Subscriber"
{
Permissions = tabledata "My Custom Ledger" = RIMD;
[EventSubscriber(ObjectType::Page, Page::"BC Table List IOI", 'OnAfterTruncateFailed', '', false, false)]
local procedure HandleAfterTruncateFailed(
TableNo: Integer;
TableName: Text[100];
var RecRef: RecordRef;
var Reseeded: Boolean;
var IsHandled: Boolean)
begin
// Handle only this extension table.
if TableNo <> Database::"My Custom Ledger" then
exit;
if TryTruncateOwnTable(RecRef) then begin
Reseeded := true;
IsHandled := true;
exit;
end;
if TryDeleteOwnTable(RecRef) then begin
Reseeded := false;
IsHandled := true;
end;
end;
[TryFunction]
local procedure TryTruncateOwnTable(var RecRef: RecordRef)
begin
RecRef.Truncate(true);
end;
[TryFunction]
local procedure TryDeleteOwnTable(var RecRef: RecordRef)
begin
RecRef.DeleteAll(true);
end;
}Recommended Implementation Pattern
- Filter by
TableNofirst. - Try
Truncate(true)in aTryFunction. - If truncate fails, try
DeleteAll(true)in aTryFunction. - Set
IsHandledandReseededonly on success. - Define
Permissionsin the subscriber codeunit for your own table data.
Notes
- DataMigrate Pro cannot predeclare permissions for future or external extension tables.
- This event is the intended extension point for partner-specific table handling.
- If your table is heavily constrained by referential logic, truncate may still fail; fallback delete handling is expected in that case.