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

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
    on at
    RE: How to get value from temporay table in Business Central Extension AL language

    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,105 Moderator on at
    RE: How to get value from temporay table in Business Central Extension AL language

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

  • Mark Lawrence Profile Picture
    30 on at
    RE: How to get value from temporay table in Business Central Extension AL language

    [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
    RE: How to get value from temporay table in Business Central Extension AL language

    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
    RE: How to get value from temporay table in Business Central Extension AL language

    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
    RE: How to get value from temporay table in Business Central Extension AL language

    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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,421

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,878 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,645 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans