Posting vendor Ledger entries through c/al code

raja123raja123 Posts: 41Member
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 Posts: 20Member
    Seems pretty simple. You do not have the permissions to modify this table.
  • BlackTigerBlackTiger Posts: 1,218Member
    There is "Application Method" field in Vendor table.
    "You can’t just ask customers what they want and then try to give that to them.
    By the time you get it built, they’ll want something new.” Steve Jobs
  • JuhlJuhl Posts: 659Member
    Don’t touch ledger tables!
    Use build in functionality.
    Follow me on my blog juhl.blog
  • mucamuca Posts: 27Member
    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 Posts: 41Member
    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 Posts: 41Member
    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 Posts: 27Member
    It seems that You have mandatory dimension AREA for this (20000) customer.
Sign In or Register to comment.