web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Sandbox Cleanup Event

Teddy Herryanto (That NAV Guy) Profile Picture Teddy Herryanto (Th... 14,068 Super User 2025 Season 2

When a sandbox is created as a copy of a production environment, BC will do the following things automatically:

  • The job queue is stopped
  • Any base application integration settings are cleared
  • Outbound HTTP calls from extensions are blocked by default and must be approved for each extension.

This is done to prevent any unwanted email / result coming from your sandbox.

What happen if you want to do the same thing with your app ?

Microsoft offers Sandbox Cleanup codeunit that you can subscribe to. It has the following events:

  • OnClearConfiguration: subscribe to this event to clean up data when copying a company to a sandbox environment.
  • OnClearCompanyConfiguration: subscribe to this event to clean up company-specific data when copying to a sandbox environment.
  • OnClearDatabaseConfiguration; subscribe to this event to clean up environment-specific data when copying to a sandbox environment.

Here is an example on how to change the company indicator text when copying to sandbox.

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sandbox Cleanup", 'OnClearCompanyConfiguration', '', false, false)]
    local procedure OnClearCompanyConfiguration(CompanyName: Text)
    var
        CompanyInfo: Record "Company Information";
    begin
        CompanyInfo.ChangeCompany(CompanyName);
        If CompanyInfo.Get() then begin
            CompanyInfo.Validate("Custom System Indicator Text", 'TEST');
            CompanyInfo.Modify();
        end;
    end;

Another way is to use the Environment Triggers codeunit which has following two events:

  • OnAfterCopyEnvironmentToSandbox
  • OnAfterCopyEnvironmentToSandboxPerCompany
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Triggers", 'OnAfterCopyEnvironmentToSandboxPerCompany', '', false, false)]
    local procedure OnAfterCopyEnvironmentToSandboxPerCompany()
    var
        CompanyInfo: Record "Company Information";
    begin
        If CompanyInfo.Get() then begin
            CompanyInfo.Validate("Custom System Indicator Text", 'TEST');
            CompanyInfo.Modify();
        end;
    end;

Be careful when using the events, because if there is an error, the sandbox creation will be canceled and you will not get any error message.


This was originally posted here.

Comments

*This post is locked for comments