{"title":"Extending the Data Archive extension","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-data-archive-extension/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-data-archive-extension, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-data-archive-extension","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Overview and examples of how to enable your app to archive data.","date":"2023-12-21","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Extending the Data Archive extension","slug":"extending-the-data-archive-extension","at":0,"chars":4947},{"level":2,"title":"Methods in the Data Archive codeunit","slug":"methods-in-the-data-archive-codeunit","at":3484,"chars":1294},{"level":2,"title":"Related information","slug":"related-information","at":4778,"chars":169}],"text":"# Extending the Data Archive extension\nThe /admin-archive-data extension provides a basic framework for archiving and backing up data as part of date compression. When you use date compression you specify a date range and all entries within the range are consolidated into a single entry, and the originals are deleted. See Compress Data with Date Compression</admin-manage-documents>. However, there might be value in keeping that data, so rather than deleting it, you can use the Data Archive extension to archive it for later use.\nThis article provides an example of how you can use the objects in the Data Archive extension so that your application can also archive data. You use the Data Archive codeunit, which is available in the System Application.\nThe following patterns of use are supported:\n Store individual records by calling the SaveRecord(Record) method.\n Store a record set by calling the SaveRecords(RecordRef) method.\n Start recording deletions by calling the StartSubscriptionToDelete() method in the beginning of your code, and StopSubscriptionToDelete() after records have been deleted. Note that this pattern records all deletions, including those that happen in related tables and intermediate tables that might be used in the process (though temporary records aren't recorded).\n> NOTE\n> Recording deletions relies on the global database triggers, so for any deletions that have already been made on the relevant records, and if the change log is not active for that table, you should consider using StartSubscriptionToDelete(true) to reset the session. Resetting the session will, however, also reset the state in the object, so we recommend caution when you test or use it.\nThe following example illustrates these patterns.\n```al\ncodeunit 50000 demo\n{\n    trigger OnRun()\n    var\n        DataArchive: Codeunit \"Data Archive\";\n    begin\n        if DataArchive.DataArchiveProviderExists() then begin\n            SaveSingleRecords();\n            SaveRecordSet();\n            DeleteAndArchiveSomeCustomers();\n        end;\n    end;\n\n    local procedure SaveSingleRecords()\n    var\n        Customer: Record Customer;\n        DataArchive: Codeunit \"Data Archive\";\n    begin\n        Customer.SetRange(\"Country/Region Code\", 'FO');\n        if Customer.FindSet() then begin\n            DataArchive.Create('Our Faroese customers');\n            repeat\n                DataArchive.SaveRecord(Customer);\n            until Customer.Next() = 0;\n            DataArchive.Save();\n        end;\n    end;\n\n    local procedure SaveRecordSet()\n    var\n        Customer: Record Customer;\n        DataArchive: Codeunit \"Data Archive\";\n        RecRef: RecordRef;\n    begin\n        Customer.SetRange(\"Country/Region Code\", 'FO');\n        if not Customer.IsEmpty() then begin\n            DataArchive.Create('Our Faroese customers');\n            RecRef.GetTable(Customer);\n            DataArchive.SaveRecords(RecRef);\n            DataArchive.Save();\n        end;\n    end;\n\n    local procedure DeleteAndArchiveSomeCustomers()\n    var\n        Customer: Record Customer;\n        DataArchive: Codeunit \"Data Archive\";\n    begin\n        Customer.SetRange(\"Country/Region Code\", 'FO');\n        if not Customer.IsEmpty() then begin\n            DataArchive.Create('Deleted Faroese customers');\n            DataArchive.StartSubscriptionToDelete();\n            Customer.DeleteAll(true);\n            DataArchive.StopSubscriptionToDelete();\n            DataArchive.Save();\n        end;\n    end;\n}\n```\n## Methods in the Data Archive codeunit\nThe following table lists the methods that the Data Archive codeunit provides.\nMethods|Description\nprocedure Create(Description: Text): Integer|Creates a new archive entry.\nprocedure CreateAndStartLoggingDeletions(Description: Text): Integer|Creates a new archive entry, resets the session and starts logging all new del\nprocedure Open(ID: Integer)|Opens an existing archive entry so more can be added to it\nprocedure Save()|Saves and closes the currently open archive entry.\nprocedure DiscardChanges()|Discards any additions and closes the currently open archive entry.\nprocedure SaveRecord(RecordVar: Variant) <br> procedure SaveRecord(var RecRef: RecordRef)|Saves the supplied record to the currently open archive entry.\nprocedure SaveRecords(var RecRef: RecordRef)|Saves all records within the filters to the currently open archive entry.\nprocedure StartSubscriptionToDelete()<br> procedure StartSubscriptionToDelete(ResetSession: Boolean)|Starts subscription to the OnDatabaseDelete trigger and calls SaveRecord with any deleted record.\nprocedure StopSubscriptionToDelete()|Stops the subscription to the OnDatabaseDelete trigger.\nprocedure DataArchiveProviderExists(): Boolean|Informs the consumer app whether there's a provider for this interface.\n## Related information\nThe Data Archive Extension</admin-archive-data>\nThe Microsoft_Application.app File<devenv-application-app-file>\ndevenv-extending-application-areas"}