Posting vendor Ledger entries through c/al code

raja123
Member Posts: 50
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:

Please help me guys.
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:

Please help me guys.
0
Best Answer
-
Your report do not have permission to modify Vendor Ledger Entries table
Set Permissions property in Your report5
Answers
-
Seems pretty simple. You do not have the permissions to modify this table.0
-
Your report do not have permission to modify Vendor Ledger Entries table
Set Permissions property in Your report5 -
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 SetApplId0 -
But after posting I'm getting this error
Which value I've to pass to this field ->GenJournalLine."Dimension Set ID" ?0 -
It seems that You have mandatory dimension AREA for this (20000) customer.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