Posting vendor Ledger entries through c/al code

raja123raja123 Member Posts: 50
edited 2019-05-27 in NAV Three Tier
My friend asked me to "Automatically apply one payment to all pending invoices for a Vendor ".

Here is my code:

Documentation()

OnInitReport()
GenJournalLine.SETRANGE("Journal Batch Name",'BANK');
GenJournalLine.SETRANGE("Journal Template Name",'PAYMENT');

OnPreReport()
GenJournalLine.INIT;
GenJournalLine."Posting Date":=020119D;
GenJournalLine."Journal Batch Name":='BANK';
GenJournalLine."Document Type":=GenJournalLine."Document Type"::Payment;
GenJournalLine."Document No.":='ADI91';
GenJournalLine."Journal Template Name":='PAYMENT';
GenJournalLine."Account Type":=GenJournalLine."Account Type"::Vendor;
GenJournalLine."Account No.":="Vendor no";
GenJournalLine."Recipient Bank Account":='ECA';
GenJournalLine."Payment Method Code":='CASH';
GenJournalLine."Bal. Account Type":=GenJournalLine."Bal. Account Type"::"Bank Account";
GenJournalLine."Bal. Account No.":='GIRO';
GenJournalLine."Applies-to Doc. Type":=GenJournalLine."Applies-to Doc. Type"::Invoice;
GenJournalLine.VALIDATE("Applies-to Doc. Type",GenJournalLine."Applies-to Doc. Type"::Invoice);


VendorLedgerEntry.SETRANGE("Vendor No.","Vendor no");
VendorLedgerEntry.SETRANGE("Document Type",VendorLedgerEntry."Document Type"::Invoice);
IF VendorLedgerEntry.FINDSET THEN
REPEAT

VendorLedgerEntry.Applies-to ID":=GenJournalLine."Documnet NO.";
VendorLedgerEntry.CALCFIELDS("Remaining Amount");
VendorLedgerEntry."Amount to Apply":=GenJournalLine."Remaining Amount";
VendorLedgerEntry.MODIFY;
UNTIL VendorLedgerEntry.NEXT=0;

GenJournalLine.Amount:=-amt;
GenJournalLine.INSERT;

OnPostReport()
CODEUNIT.RUN(CODEUNIT::"Gen. Jnl.-Post",GenJournalLine);

But I'm getting this error:

ipmxxcmsdefk.png



Please help me guys.

Best Answer

Answers

  • midegomidego Member Posts: 51
    Seems pretty simple. You do not have the permissions to modify this table.
  • JuhlJuhl Member Posts: 724
    Don’t touch ledger tables!
    Use build in functionality.
    Follow me on my blog juhl.blog
  • mucamuca Member Posts: 42
    Yes. It's not a best practice. (You will get the same function in multiple places)
    but basically it do the same as Codeunit 111 Vend. Entry-SetAppl.ID function SetApplId
  • raja123raja123 Member Posts: 50
    muca wrote: »
    Yes. It's not a best practice. (You will get the same function in multiple places)
    but basically it do the same as Codeunit 111 Vend. Entry-SetAppl.ID function SetApplId

    Yeah , You are Right.
  • raja123raja123 Member Posts: 50
    edited 2019-05-28
    raja123 wrote: »
    muca wrote: »
    Yes. It's not a best practice. (You will get the same function in multiple places)
    but basically it do the same as Codeunit 111 Vend. Entry-SetAppl.ID function SetApplId

    Yeah , You are Right.

    But after posting I'm getting this error
    vj8hzw4tu0xb.png

    Which value I've to pass to this field ->GenJournalLine."Dimension Set ID" ?
  • mucamuca Member Posts: 42
    It seems that You have mandatory dimension AREA for this (20000) customer.
Sign In or Register to comment.