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 :
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.

I have the same question (0)
  • 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

  • Suggested answer
    Dallefeld Profile Picture
    193 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
    YUN ZHU Profile Picture
    93,438 Super User 2025 Season 2 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
    Nitin Verma Profile Picture
    21,696 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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,204

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,933

#3
YUN ZHU Profile Picture

YUN ZHU 1,885 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans