Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Modify base application codeunit or create extension to add on to it

(1) ShareShare
ReportReport
Posted on by 77

Hello, I've created an extension that adds an additional field in the Sales Order table & page (called Document Revision Number). But we have noticed that when we archive the sales order, it moves to a new table (Sales Order Archive) which does not have that field, so the information is lost. I need to figure out how to have it keep that field when it moves to the archive. The two things I need do are:

  1. Create the same field in the Sales Order Archive table
  2. Figure out how to have the codeunit that archives a Sales Order also archive my custom field. I assume I cannot directly edit the codeunit, but I need to create an extension to add on to it.

The problem is, the only thing I've found online is about events. I haven't been able to figure out how to create an event subscriber that would accomplish this. Any advice is appreciated.

  • Suggested answer
    Nitin Verma Profile Picture
    21,571 Moderator on at
    RE: Modify base application codeunit or create extension to add on to it

    For the all old records which dont have that field you can go with Vaishnavi suggestion but for every new records you can create the same field with same ID in Sales header and Sales Archive Header table. so that I will transferred automatically when you will do the archive.

  • Suggested answer
    YUN ZHU Profile Picture
    86,083 Super User 2025 Season 1 on at
    RE: Modify base application codeunit or create extension to add on to it

    Hi, Vaishnavi gave good examples, you can also look for clues yourself in codeunit 5063 ArchiveManagement.

    For example, this is the event used by Vaishnavi.

    pastedimage1657843456615v1.png

    Also, although I haven't tried it, the event below should work as well.

    pastedimage1657843582850v2.png

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Dallefeld Profile Picture
    175 User Group Leader on at
    RE: Modify base application codeunit or create extension to add on to it

    Vaishnavi gave you the answer...make the field number is sales header and sales header archive and BC takes care of the rest!

  • Suggested answer
    Vaishnavi J Profile Picture
    3,060 on at
    RE: Modify base application codeunit or create extension to add on to it

    Hi,

    Create a field in Sales Order Archive table and display it on page.

    Please note if the Field No in Sales Order table and Sales Order Archive table is same then you don't need to add the below logic the code unit part.

    Generally Microsoft uses Transferfield function when transferring the data in two different tables if the Field No. is same then transferfield function will set the data in Archive Table. 

    if the Field No. are different in both the tables then you have to write the below logic .

    codeunit 50044 Events

    {
        Permissions = tabledata Rec_SalesHeaderArchieve = RIMD;

        [EventSubscriber(ObjectType::Codeunit, Codeunit::ArchiveManagement, 'OnAfterAutoArchiveSalesDocument', '', false, false)]
        local procedure OnAfterAutoArchiveSalesDocument(var SalesHeader: Record "Sales Header")
        var
            Rec_SalesHeaderArchieve: Record "Sales Header Archive";
        begin
           Clear(Rec_SalesHeaderArchieve);
            Rec_SalesHeaderArchieve.Reset();
            Rec_SalesHeaderArchieve.SetRange("Document Type", Rec_SalesHeaderArchieve."Document Type"::Order);
            Rec_SalesHeaderArchieve.SetRange("Document Date", SalesHeader."Document Date");
            Rec_SalesHeaderArchieve.SetRange("No.", SalesHeader."No.");
            Rec_SalesHeaderArchieve.SetRange("Version No.", SalesHeader."No. of Archived Versions");
            if Rec_SalesHeaderArchieve.FindFirst() then begin
                Rec_SalesHeaderArchieve.Document Revision Number := SalesHeader.Document Revision Number;
                Rec_SalesHeaderArchieve.Modify(true);
            end;
        end;
    }

    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans