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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Active Discussion

Cleaning Posted general ledger Entries one time job

(6) ShareShare
ReportReport
Posted on by 990

HI,

I need to develop an action in the posted ledger entries page and delete the transactions which are posted.This would be a one time job and this is so that we can take the system to the starting point with respect to this.I tries adding an action delete in a new page extension  which is false for this page in the base code.

Now when I try deleting the code at the follwing line there is an Error Pop out in the UI :

pageextension 50291 generalLedgerExt extends "General Ledger Entries"
{

    actions
    {

        addafter(ReverseTransaction)
        {
            action(Delete)
            {
                ApplicationArea = All;
                trigger OnAction()
                var
                    BlankDate: Date;
                begin
                    if rec."Posting Date" <> BlankDate then begin
                        rec.SetCurrentKey("Posting Date");
                        rec.SetRange("Posting Date");
                        if rec.FindSet() then begin
                            repeat
                                rec.Delete();///Exception is do not have the license to delete the journals
                            until Next() 0;
                        end;

                    end;


                end;

            }

        }
    }

}
8372.pastedimage1612273419940v1.png

1452.pastedimage1612273432507v2.png
I tried adding permissions to the G/L entry but it shows conflict and not able to delete.
Please advice.
Regards,
Indira
  • Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

  • Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at

    Firstly, Why are you deleting posted entries, you should not delete the entries, if you want to correct something you need to post credit memos.  

    This is a very bad design.

  • JAngle Profile Picture
    152 on at

    Is this to be done in a production environment? There is a way to do it but reluctant to provide the answer given how destructive this could be. There is a reverse feature for journal postings and as Suresh says a chance to do credits for document postings. You do now have a feature that can be turned on at journal template level that enables journal postings to be saved. This means a user can then access archived journals to post as reversals in one large batch. Less of a limitation than the first reversal feature I mentioned as that only does one batch at a time

  • Suggested answer
    Steven Renders Profile Picture
    5,686 Moderator on at
    I strongly recommend not to do this!
     
    Do not delete anything in Posted tables or Ledger Entry tables. You can, and probably will, leave the database and accounting in an inconsistent state.
     
    Instead use the Data Administration guide and archive the 'old' data:
  • Suggested answer
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at
    We don't recommend doing this. Are you considering it because you want to use the same company for production after some testing has been completed, and now you want to clear all the transactional data? Or are you already live and trying to undo something? 

    If you're attempting to undo something, then don't use this method. However, if your intention is to use the same company after User Acceptance Testing (UAT), you can proceed, to fix the error you'll need to create a new codeunit or report and specify permissions at the object level for the tabledata G/L Entry Table, as this will allow you to proceed with the action.
     
     
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,132 Super User 2026 Season 1 on at
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    9,112 Super User 2026 Season 1 on at

    Hi Indira,

    Attempting to delete posted G/L entries directly from the “General Ledger Entries” page will trigger a permission error, even with super user rights. This is by design: posted entries are protected to preserve audit integrity, and deletion is restricted at both the platform and license level.

    Here’s what’s happening and how to approach it:

    • The error message confirms that your license does not include delete permissions for TableData G/L Entry. Even if you add permissions in AL, BC enforces object-level restrictions on posted tables like G/L Entry, Customer Ledger Entry, Vendor Ledger Entry, etc.
    • The rec.Delete() line in your page extension will always fail unless:
      • You run the code from a codeunit or report with explicit Permissions = TableData "G/L Entry" = D;
      • You compile and publish the extension with a partner/developer license that allows destructive operations
      • You execute the deletion in a sandbox or test environment, not production
    • Even then, deleting posted entries is strongly discouraged. It can break audit trails, cause data inconsistencies, and violate compliance standards.


    Safer alternatives:

    • If your goal is to reset the environment after UAT or testing:
      • Use the Data Administration tools to archive or purge transactional data
      • Create a new company using Copy Company or RapidStart Services
      • Use retention policies or filtered views to hide old entries
    • If you must delete for a one-time reset:
      • Create a codeunit or report with elevated permissions
      • Run it in a sandbox with full backup
      • Document the deletion and ensure no dependencies (e.g., posted documents, VAT entries, audit logs)


    Helpful references:

    Clean Up Data with Retention Policies – Microsoft Learn
    Archive Sales, Purchase, and Service Documents – Microsoft Learn
    Posted General Journal Cleanup – Dynamics Community
    Managing and Correcting Posted Journals – BC Insight
    Delete Posted Entries Safely – Dynamics Forum
    Use Copy Journal Function – Microsoft Docs



    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

  • Suggested answer
    Sohail Ahmed Profile Picture
    11,169 Super User 2026 Season 1 on at
    You cannot delete posted General Ledger Entries via AL code due to license and data integrity restrictions. The recommended approach is to create a new company for a fresh start.
     
    ✅ Mark this answer as verified if it helps you.
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,993 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,116 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 557 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans