I have made a custom table to copy whole data which is already posted in BANK ACCOUNT LEDGER ENTRY table .I am able to do it for once via job queue code that I have written but for new Records in bank ledger entries it is not working. Also,I have 1 field whixh is directly coming from GENERAL JOURNAL line but for that I have used same field Id.
this is the codeunit that i have used
Try this code
codeunit 90127 BankAccountLedgerEntryCustom { VAR SourceTableVar: Record "Bank Account Ledger Entry"; DestinationTableVar: Record BALTable; trigger OnRun() BEGIN SourceTableVar.RESET; SourceTableVar.setrange("Entry No."); SourceTableVar.findlast; DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No."); if (DestinationTableVar.FindSet()) then begin DestinationTableVar."Statement Status" := SourceTableVar."Statement Status"; DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No."; DestinationTableVar."Statement No." := SourceTableVar."Statement No."; DestinationTableVar.Modify; end else begin DestinationTableVar.INIT(); DestinationTableVar."Entry No." := SourceTableVar."Entry No."; DestinationTableVar.Amount := SourceTableVar.Amount; DestinationTableVar."Amount (LCY)" := SourceTableVar."Amount (LCY)"; DestinationTableVar.INSERT(); end; END; }
hi this code that you provided is not working for entries which are already present and needed to be updated for fields Statement no,line etc.
yeah, a.c to your code.. if entry no. is not found in the destination table then it will insert the record in your source table.. if entry no. is found in the destination table then it will only update those fields..
if entry no. is found in destination table then will this code only update the following fields?
DestinationTableVar."Statement Status" := SourceTableVar."Statement Status";
DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No.";
DestinationTableVar."Statement No.":= SourceTableVar."Statement No.";
DestinationTableVar.modify;
It worked for me but when i am posting data fro m General Journal in which I have added some fields.While posting it,those fields are not coming in gen. journal table and therefore by assigning same field id i am not able to show them in mt custom table as well.What should i do about it.
Hi, it feels like a trigger problem. It is recommended that you put this code in the OnInsert of the table. If it is placed in the OnInsertRecord of the Page, it will only run on that page.
Hope this can give you some hints.
Thanks.
ZHU
Hi,
You can try below code
codeunit 90127 BankAccountLedgerEntryCustom { VAR SourceTableVar: Record "Bank Account Ledger Entry"; DestinationTableVar: Record BALTable; trigger OnRun() BEGIN SourceTableVar.RESET; SourceTableVar.setrange("Entry No."); SourceTableVar.findlast; DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No."); IF not DestinationTableVar.FINDSET() THEN BEGIN REPEAT DestinationTableVar.INIT(); DestinationTableVar."Entry No." := SourceTableVar."Entry No."; DestinationTableVar.Amount := SourceTableVar.Amount; DestinationTableVar."Amount (LCY)" := SourceTableVar."Amount (LCY)"; DestinationTableVar.INSERT(); UNTIL SourceTableVar.NEXT = 0; END else begin DestinationTableVar."Statement Status" := SourceTableVar."Statement Status"; DestinationTableVar."Statement Line No." := SourceTableVar."Statement Line No."; DestinationTableVar."Statement No.":= SourceTableVar."Statement No."; DestinationTableVar.modify; end; END; }
I assume what you are trying to achieve here is to find the last entry in the source table with this code:
SourceTableVar.RESET;
DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
So you should try to add the findlast line and see if that helps you.
The problem I think is that the sourcetable does not hold a record when you try to get the Entry No. in your setrange statement,
SourceTableVar.RESET;
SourceTable.FindLast();
DestinationTableVar.SetRange("Entry No.", SourceTableVar."Entry No.");
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156