Adding extension to Preview Posting Business Central AL Extension

jhanvincent14
Member Posts: 214
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.
Everytime I do debug. my tempsapleentry table is always empty on OnAfterFillDocumentEntry
Here is my code:
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.
Everytime I do debug. my tempsapleentry table is always empty on OnAfterFillDocumentEntry
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; }
0
Best Answer
-
Hi, @jhanvincent14 I've found the solution. Set the 'SingleInstance' property of your Codeunit to true. It should do the trick
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.2
Answers
-
Hi, try initialize to the tempSampleEnty table, do a FINDSET.tempSampleEnty, for example.0
-
Hi, @jhanvincent14 I have the same problem, have you found the solution for this?0
-
I am not sure if a temporary table could be used in that way. I have not seen any example. Is there any example in the standard?United Kingdom0
-
Hi, @jhanvincent14 I've found the solution. Set the 'SingleInstance' property of your Codeunit to true. It should do the trick
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.2 -
-
@jhanvincent14 did you finished that code. if you have the correct code so pls give me i need . pls helpme
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions