Creating New G/L Entries

omyvadiya
Member Posts: 124
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.
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
-
The correct way is using the general journal routines std. NAV offers.
This whay the data stays consistent.
https://docs.microsoft.com/nl-nl/dynamics-nav-app/design-details-posting-engine-structure0 -
Hi @TallyHo ,
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 so0 -
Post a general journal manually in NAV.
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.1 -
Like TallyHo said, you should write your code to fill the values in Gen. Journal Line table then use the standard function to Post your line to G/L entry table.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