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...
Suggested Answer

How to get value from temporay table in Business Central Extension AL language

(1) ShareShare
ReportReport
Posted on by 30

Hi,

I have an event EventSubscriber for SampleTable OnAfterInsertEvent to populate the tempSampleEnty temp table and another EventSubscriber to another Codeunit 20 (Posting Preview Event Handler) for the event "OnAfterFillDocumentEntry" to add new row in POSTING PREVIEW window but my temporary table is uninitialized or empty when Im using it in InsertDocumentEntry function.

Here is my code:

codeunit 99999 "SampleTableHandler"
{
var
tempSampleEnty : Record "Sample Table" temporary;
PostPrevHandler : Codeunit "Posting Preview Event Handler";

[EventSubscriber(ObjectType::Table, 99991, 'OnAfterInsertEvent', '', true, true)]
procedure OnInsertSampleEntry(VAR Rec: Record "SampleTable");
begin
if Rec.IsTemporary then
exit;
PostPrevHandler.PreventCommit();
tempSampleEnty := Rec;
tempSampleEnty."Document No." := '***';
tempSampleEnty.INSERT;
end;

[EventSubscriber(ObjectType::Codeunit, 20, 'OnAfterFillDocumentEntry', '', true, true)]
procedure InsertSampleDocumentEntry(VAR DocumentEntry: Record "Document Entry");
begin
PostPrevHandler.InsertDocumentEntry(tempSampleEnty, DocumentEntry);
end;
}

Thanks.

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

  • Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    I cant't see that you put any data into your tempSampleEnty anywhere?

  • Mark Lawrence Profile Picture
    30 on at

    [EventSubscriber(ObjectType::Table, 99991, 'OnAfterInsertEvent', '', true, true)]

    procedure OnInsertSampleEntry(VAR Rec: Record "SampleTable");

    begin

         if Rec.IsTemporary then

         exit;

         PostPrevHandler.PreventCommit();

        //code to put the data

         tempSampleEnty := Rec;

         tempSampleEnty."Document No." := '***';

         tempSampleEnty.INSERT;

    end;

  • Kenji Motomatsu Profile Picture
    140 on at

    HI Mark, did you ever find out how to handle your situation? We're faced with similar requirement, and wanted to understand how we can subscribe to "Posting Preview Event Handler" events to properly display document entries, when using Preview Posting.

  • jvillasin Profile Picture
    30 on at

    Does anyone have the answer for this on how to ? im having the same problem right  now

  • Suggested answer
    Mario Sopena Profile Picture
    5 on at

    Hi, try setting the 'SingleInstance' property of your Codeunit to true. Remember to 'clear' your temporary variable before starting the posting preview as it is instanciated once.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Preview", 'OnBeforeRunPreview', '', true, true)]

    local procedure OnBeforeRunPreview(Subscriber: Variant; RecVar: Variant)
    var
        SampleTableHandler: Codeunit "SampleTableHandler";
    begin
        SampleTableHandler.ClearTempEntries();
    end;
    I said 'clear' because Clear(tempSampleEntry) is not enough. You must Delete all records from your temp variable.
    Hope this help!

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,965 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,125 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 961 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans