Hi,
What is the correct process/way to create new G/L Lines via coding while posting a sales invoice, ship & receive are at the same time.
What i tried:
1. created the new fields that are also to be transferred from a custom table at Sales Invoice page to G/l Entry table.
2. Tried filtering the new table data with G/L entry in cdu - 12 in InsertGLEntry(it didn't worked,on debugging the filter didn't workd with document no.)
3. Tried filtering the new table data with G/L entry in cdu - 12 in CreateGLEntry(it didn't worked,on debugging the filter didn't workd with document no.)
4. Lastly at the End on the OnRun of Cdu-80 (i know that's not the correct way)
Code that i wrote:
//Payment Mode - GL entry creation Start->
PaymentModeRec.RESET;
PaymentModeRec.SETFILTER("Document Type",'%1',GLEntry."Document Type"::Invoice);
PaymentModeRec.SETRANGE("Document No.",GLEntry."Document No.");
IF PaymentModeRec.FINDFIRST THEN BEGIN
REPEAT
PaymentGL.INIT;
PaymentGL."Entry No." := GLEntry."Entry No." + 1;
PaymentGL."Document Type" := PaymentModeRec."Document Type"::Invoice;
PaymentGL."Document No." := PaymentModeRec."Document No.";
PaymentGL."Bal. Account Type" := PaymentModeRec."Bal. Account Type";
PaymentGL."Bal. Account No." := PaymentModeRec."Bal. Account No.";
IF PaymentModeRec."Bal. Account Type" = PaymentModeRec."Bal. Account Type"::"Bank Account" THEN BEGIN
BankAccount.RESET;
BankAccount.SETRANGE("No.",PaymentModeRec."Bal. Account No.");
IF BankAccount.FINDFIRST THEN;
PaymentGL."G/L Account Name" := PaymentModeRec."Bank Name";
END;
PaymentGL.Amount := PaymentModeRec."Payment Amount";
PaymentGL."Ref. No." := PaymentModeRec."Ref. No.";
PaymentGL."Ref. Date" := PaymentModeRec."Ref. Date";
PaymentGL."No. of EMI" := PaymentModeRec."No. Of Emi.";
PaymentGL."Payment Mode" := TRUE;
PaymentGL.INSERT;
UNTIL PaymentModeRec.NEXT = 0;
END;
//Payment Mode - GL entry creation Stop <-
what is the correct way to create gl lines that doesn't create deadlock and doesn't slows down the system.
0
Answers
This whay the data stays consistent.
https://docs.microsoft.com/nl-nl/dynamics-nav-app/design-details-posting-engine-structure
I tried the same on the OnInsertGLEntry function earlier too, after your post, i have written the same on the OnInsertGLEntry function but the setrange isn't working, the code didn't worked, the glentry.document no. isn't matching in the function.
The glentry.document no. is not matching the invoice no. that i am posting.
That's why it isn;t going into the .init, .insert loop.
i am not getting it why is it so
Fill your general journal in the way you want the gl entry to become.
Test this.
After that fill a GenJnlLine rec variable the same way
Run GenJnlPostLine.RunWithCheck(GenJnlLine) to get your gl entries.