web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Payment List page takes too long time too open

(1) ShareShare
ReportReport
Posted on by 58

vendor payment have 1000+ entries and it opens up on click of 3 buttons vendor payment button , 2. pending vendor payment 3.approved vendor payment 4. create bank payment button , on click of every button vendor payment page opens up status wise , 
Action 1- Show vendor payment -> vendor payment will open with filter status = Open
action 2- Pending Vendor Paymnet - Vendor payment will open with filter status = Pending
action 3- Approved - vendor payment with approved status will open 
action 4 -Create Payment button - vendor paymnet with some calculations and status approved will open 
figure out what can be the problem
 

page 50271 "Advance And Vendor Payment"
{
    PageType = Card;
    ApplicationArea = All;
    Caption = 'Advance / Vendor Payment';
    UsageCategory = Administration;
 
    layout
    {
        area(Content)
        {
            group(GroupName)
            {
 
            }
        }
    }
 
    actions
    {
        area(Processing)
        {
            action("Show Advance Payment")
            {
                Caption = 'Show Advance Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    AdvPmtRec: Record "Payment Terms Line Purchase";
                    AdvPmtPage: Page "Advance Pmt Terms Line Purch";
                begin
                    AdvPmtRec.FilterGroup(8);
                    AdvPmtRec.SetRange("Table ID", 38);
                    AdvPmtRec.SetRange("Transaction Type", AdvPmtRec."Transaction Type"::Purchase);
                    AdvPmtRec.SetRange("Document Type", AdvPmtRec."Document Type"::Order);
                    AdvPmtRec.SetRange("Main Payment Type", AdvPmtRec."Main Payment Type"::Advance);
                    AdvPmtRec.SetRange(Status, AdvPmtRec.Status::Released);
                    AdvPmtRec.SetFilter("Approval Status", '<>%1', AdvPmtRec."Approval Status"::Approved);
                    //Page.Run(Page::"Advance Pmt Terms Line Purch", AdvPmtRec);
 
                    Clear(AdvPmtPage);
                    AdvPmtPage.CalforSendApp(true);
                    AdvPmtPage.SetTableView(AdvPmtRec);
                    AdvPmtPage.Run();
                end;
 
            }
            action("Vendor Payment")
            {
                Caption = 'Vendor Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VenPay: Page "Vendor Payment";
                    VenLedEntry: Record "Vendor Ledger Entry";
                begin
                    VenLedEntry.FilterGroup(2);
                    VenLedEntry.SetFilter("Approval Status", '<>%1', VenLedEntry."Approval Status"::Approved);
                    Clear(VenPay);
                    VenPay.CalforSendApp(true);
                    VenPay.SetTableView(VenLedEntry);
                    VenPay.Run();
                    //Page.Run(Page::"Vendor Payment", VenLedEntry);
                end;
 
            }
 
            action("Pending Advance Payment")
            {
                Caption = 'Pending Advance Payment';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
 
                trigger OnAction()
                var
                    AdvPmtRec: Record "Payment Terms Line Purchase";
                    ShowAdvancePaymentForm: Page "Advance Pmt Terms Line Purch";
                    PaymentTermLinePurch: Record "Payment Terms Line Purchase";
                    ApprovalEntry: Record "Approval Entry";
                begin
 
                    //Show set of entry to approve for assigned user
                    PaymentTermLinePurch.Reset();
                    PaymentTermLinePurch.SetRange("Table ID", 38);
                    PaymentTermLinePurch.SetRange("Transaction Type", PaymentTermLinePurch."Transaction Type"::Purchase);
                    PaymentTermLinePurch.SetRange("Document Type", PaymentTermLinePurch."Document Type"::Order);
                    PaymentTermLinePurch.SetRange("Main Payment Type", PaymentTermLinePurch."Main Payment Type"::Advance);
                    PaymentTermLinePurch.SetRange(Status, PaymentTermLinePurch.Status::Released);
                    PaymentTermLinePurch.SetRange("Approval Status", PaymentTermLinePurch."Approval Status"::"Pending for Approval");
                    if PaymentTermLinePurch.FindSet() then
                        repeat
                            ApprovalEntry.Reset();
                            ApprovalEntry.SetRange("Table ID", 97725);//RecordID.TableNo
                            ApprovalEntry.SetRange("Record ID to Approve", PaymentTermLinePurch.RecordID);
                            ApprovalEntry.SetRange(Status, ApprovalEntry.Status::Open);
                            ApprovalEntry.SetRange("Approver ID", UserId);
                            ApprovalEntry.SetRange("Related to Change", false);
                            if ApprovalEntry.FindFirst() then
                                PaymentTermLinePurch.Mark(true)
                        until PaymentTermLinePurch.Next() = 0;
                    PaymentTermLinePurch.MARKEDONLY(TRUE);
 
                    Clear(ShowAdvancePaymentForm);
                    ShowAdvancePaymentForm.CalformApprove(true);
                    ShowAdvancePaymentForm.SetTableView(PaymentTermLinePurch);
                    ShowAdvancePaymentForm.Run();
                    // Page.Run(Page::"Advance Pmt Terms Line Purch", PaymentTermLinePurch);
 
                end;
 
            }
 
            action("Pending Vendor Payment")
            {
                Caption = 'Pending Vendor Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
 
                trigger OnAction()
                var
                    AppEntryListPage: page "Approval Entries";
                    RequestsToApprovePage: Page "Requests to Approve";
                    VendLedEntry: Record "Vendor Ledger Entry";
                    ApprovalEntry: Record "Approval Entry";
                    VendPaymentForm: Page "Vendor Payment";
                begin
                    VendLedEntry.Reset();
                    VendLedEntry.SetAutoCalcFields("Remaining Amount");
                    VendLedEntry.SetRange(VendLedEntry."Document Type", VendLedEntry."Document Type"::Invoice);
                    VendLedEntry.SetFilter("Remaining Amount", '<%1', 0);
                    VendLedEntry.SetRange("Approval Status", VendLedEntry."Approval Status"::"Pending for Approval");
                    if VendLedEntry.FindSet() then
                        repeat
                            ApprovalEntry.Reset();
                            ApprovalEntry.SetRange("Table ID", 25);//RecordID.TableNo
                            ApprovalEntry.SetRange("Record ID to Approve", VendLedEntry.RecordID);
                            ApprovalEntry.SetRange(Status, ApprovalEntry.Status::Open);
                            ApprovalEntry.SetRange("Approver ID", UserId);
                            ApprovalEntry.SetRange("Related to Change", false);
                            if ApprovalEntry.FindFirst() then
                                VendLedEntry.Mark(true)
                        until VendLedEntry.Next() = 0;
                    VendLedEntry.MARKEDONLY(TRUE);
 
                    Clear(VendPaymentForm);
                    VendPaymentForm.CalformApprove(true);
                    VendPaymentForm.SetTableView(VendLedEntry);
                    VendPaymentForm.Run();
 
                    //Page.Run(Page::"Vendor Payment", VendLedEntry);
 
                end;
 
            }
 
            action("Approved Advance Payment")
            {
                Caption = 'Approved Advance Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
 
                trigger OnAction()
                var
                    AdvPmtRec: Record "Payment Terms Line Purchase";
                    AdvPmtPage: Page "Advance Pmt Terms Line Purch";
                begin
                    AdvPmtRec.FilterGroup(8);
                    AdvPmtRec.SetRange("Table ID", 38);
                    AdvPmtRec.SetRange("Transaction Type", AdvPmtRec."Transaction Type"::Purchase);
                    AdvPmtRec.SetRange("Document Type", AdvPmtRec."Document Type"::Order);
                    AdvPmtRec.SetRange("Main Payment Type", AdvPmtRec."Main Payment Type"::Advance);
                    AdvPmtRec.SetRange(Status, AdvPmtRec.Status::Released);
                    AdvPmtRec.SetFilter("Approval Status", '=%1', AdvPmtRec."Approval Status"::Approved);
                    //Page.Run(Page::"Advance Pmt Terms Line Purch", AdvPmtRec);
 
                    Clear(AdvPmtPage);
                    //AdvPmtPage.CalforBankPay(true);
                    AdvPmtPage.SetTableView(AdvPmtRec);
                    AdvPmtPage.Run();
                end;
 
            }
            action("Approved Vendor Payment")
            {
                Caption = 'Approved Vendor Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VenPay: Page "Vendor Payment";
                    VendLedEntry: Record "Vendor Ledger Entry";
 
                begin
                    VendLedEntry.Reset();
                    VendLedEntry.FilterGroup(4);
                    VendLedEntry.SetAutoCalcFields("Remaining Amount");
                    VendLedEntry.SetRange(VendLedEntry."Document Type", VendLedEntry."Document Type"::Invoice);
                    VendLedEntry.SetFilter("Remaining Amount", '<%1', 0);
                    VendLedEntry.SetRange("Approval Status", VendLedEntry."Approval Status"::Approved);
                    //Page.Run(Page::"Vendor Payment", VendLedEntry);
                    Clear(VenPay);
                    //VenPay.CalforBankPay(true);
                    VenPay.SetTableView(VendLedEntry);
                    VenPay.Run();
                end;
 
            }
            action("Create Bank Payment for Advance")
            {
                Caption = 'Create Bank Payment for Advance';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                Visible = show;
                trigger OnAction()
                var
                    AdvPmtRec: Record "Payment Terms Line Purchase";
                    AdvPmtPage: Page "Advance Pmt Terms Line Purch";
                begin
                    AdvPmtRec.FilterGroup(8);
                    AdvPmtRec.SetRange("Table ID", 38);
                    AdvPmtRec.SetRange("Transaction Type", AdvPmtRec."Transaction Type"::Purchase);
                    AdvPmtRec.SetRange("Document Type", AdvPmtRec."Document Type"::Order);
                    AdvPmtRec.SetRange("Main Payment Type", AdvPmtRec."Main Payment Type"::Advance);
                    AdvPmtRec.SetRange(Status, AdvPmtRec.Status::Released);
                    AdvPmtRec.SetFilter("Approval Status", '=%1', AdvPmtRec."Approval Status"::Approved);
                    //Page.Run(Page::"Advance Pmt Terms Line Purch", AdvPmtRec);
 
                    Clear(AdvPmtPage);
                    AdvPmtPage.CalforBankPay(true);
                    AdvPmtPage.SetTableView(AdvPmtRec);
                    AdvPmtPage.Run();
                end;
 
            }
 
            action("Create Bank Payment for Vendor Payment")
            {
                Caption = 'Create Bank Payment for Vendor Payment';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                Visible = show;
                trigger OnAction()
                begin
                    VendLedEntry.Reset();
                    VendLedEntry.SetAutoCalcFields("Remaining Amount");
                    VendLedEntry.SetRange(VendLedEntry."Document Type", VendLedEntry."Document Type"::Invoice);
                    VendLedEntry.SetFilter("Remaining Amount", '<%1', 0);
                    VendLedEntry.SetRange("Approval Status", VendLedEntry."Approval Status"::Approved);
                    if VendLedEntry.FindSet() then;
 
                    Clear(VendPaymentForm);
                    VendPaymentForm.CalforBankPay(true);
                    VendPaymentForm.SetTableView(VendLedEntry);
                    VendPaymentForm.Run();
                end;
 
            }
            action("Payment History")
            {
                Caption = 'Payment History';
                ApplicationArea = all;
                Promoted = true;
                PromotedCategory = Process;
                //Visible = show;
                RunObject = page "Payment History";
 
            }
 
        }
    }
 
    trigger OnOpenPage()
    begin
        UserSetup.Get(UserId);
        if UserSetup."Create Advance Bank Payment" then
            show := true;
    end;
 
    var
        UserSetup: Record "User Setup";
        VendLedEntry: Record "Vendor Ledger Entry";
        ApprovalEntry: Record "Approval Entry";
        VendPaymentForm: page "Vendor Payment";
        ShowAdvancePaymentForm: Page "Advance Pmt Terms Line Purch";
        PaymentTermLinePurch: Record "Payment Terms Line Purchase";
        show: Boolean;
 
}



here is the original page - 
page 50153 "Vendor Payment"
{
    PageType = List;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = "Vendor Ledger Entry";
    SourceTableView = where("Document Type" = const(Invoice), "Remaining Amount" = filter(< 0), "Vendor Posting Group" = filter(<> 'BRANCH'));
    InsertAllowed = false;
    DeleteAllowed = false;
    Permissions = tabledata "Vendor Ledger Entry" = M, tabledata "Payment Terms Line Purchase" = M, tabledata "Item Ledger Entry" = RM;
    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field("Posting Date"; Rec."Posting Date")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Document Date"; Rec."Document Date")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Due Date"; Rec."Due Date")
                {
                    ApplicationArea = All;
                    Editable = IsEditable;
                }
                field("Prepayment Due Date"; Rec."Prepayment Due Date")
                {
                    ApplicationArea = all;
                    Caption = 'Prepayment Due Date';
                    Editable = false;
                }
 
                field("Document Type"; Rec."Document Type")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Document No."; Rec."Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Approval Status"; Rec."Approval Status")
                {
                    ApplicationArea = All;
                    Editable = false;
                    Caption = 'Payment Approval';
 
                }
 
                field("Sender ID"; Rec."Sender ID")
                {
                    ApplicationArea = all;
                    Editable = false;
                    Visible = calforApprove;
                }
                field("Approver ID"; Rec."Approver ID")
                {
                    ApplicationArea = all;
                    Editable = false;
                    //Visible = calforApprove;
                }
 
                // field("Item Category"; ItemCategory)
                // {
                //     ApplicationArea = all;
                //     Editable = false;
                // }
                field("Item Category Code"; Rec."Item Category Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("External Document No."; Rec."External Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Reference Document No."; Rec."Reference Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Vendor No."; Rec."Vendor No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Vendor Name"; Rec."Vendor Name")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Global Dimension 2 Code"; Rec."Global Dimension 2 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Global Dimension 1 Code"; Rec."Global Dimension 1 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Project Name"; ProjectName)
                {
                    ApplicationArea = all;
                    Editable = false;
                }
                field("Shortcut Dimension 3 Code"; Rec."Shortcut Dimension 3 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Shortcut Dimension 4 Code"; Rec."Shortcut Dimension 4 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                // field("Shortcut Dimension 5 Code"; Rec."Shortcut Dimension 5 Code")
                // {
                //     ApplicationArea = All;
                //     Editable = false;
                // }
                field(Department; Rec.Department)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Shortcut Dimension 8 Code"; Rec."Shortcut Dimension 8 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field(Amount; Rec.Amount)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Remaining Amount"; Rec."Remaining Amount")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("To be Paid"; Rec."To be Paid")
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    begin
                        if Rec."To be Paid" > Abs(Rec."Remaining Amount") then
                            Error('To be Paid Must be Less than or equal to Remaining Amount!');
                    end;
                }
                field("Payment On Hold"; Rec."Payment On Hold")
                {
                    ApplicationArea = All;
                    Editable = false;//calfromBankPay;
                }
                field("Payment Rejection Comment"; Rec."Payment Rejection Comment")
                {
                    ApplicationArea = All;
                    Editable = false;//calfromBankPay;
                }
                field("Payment Rejected"; Rec."Payment Rejected")
                {
                    ApplicationArea = All;
                    Editable = false;// calfromBankPay;
                    trigger OnValidate()
                    var
                        myInt: Integer;
                    begin
                        if Rec."Payment Rejected" then begin
                            Rec.TestField("Payment Rejection Comment");
                            Rec."Approval Status" := Rec."Approval Status"::Open;
                            Rec."Payment Rejected" := false;
                            CurrPage.Update();
                        end
                        else if Rec."Payment Rejection Comment" <> '' then
                            Error('Payment Rejection Comment Must be Blank!');
                    end;
                }
                field("Entry No."; Rec."Entry No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field(Open; Rec.Open)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Location Code"; Rec."Location Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Payment Entry Created"; Rec."Payment Entry Created")
                {
                    ApplicationArea = all;
                    Editable = false;
                }
                field("PO Remarks"; PORemarks)
                {
                    ApplicationArea = all;
                    Editable = false;
                }
 
            }
        }
        area(Factboxes)
        {
 
        }
    }
 
    actions
    {
        area(Processing)
        {
            action(SendApprovalRequest)
            {
                ApplicationArea = all;
                Caption = 'Send A&pproval Request';
                Image = SendApprovalRequest;
                Visible = calforsendap;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                ToolTip = 'Executes the Send A&pproval Request action.';
                trigger OnAction()
                var
                    WorkflowEvent: Codeunit "Workflow Events";
                    vendLedEntry: Record "Vendor Ledger Entry";
                    GenEvent: Codeunit "General Events";
                begin
                    IF WorkflowEvent.CheckVendorPaymentApprovalsWorkflowEnabled(Rec) THEN begin
                        CurrPage.SetSelectionFilter(vendLedEntry);
                        if vendLedEntry.FindSet() then
                            repeat
                                //RKS290126-
                                vendLedEntry.CalcFields("Remaining Amount");
                                if vendLedEntry."To be Paid" = 0 then
                                    GenEvent.CheckPOPayment(vendLedEntry."Reference Document No.", -1 * ROUND(vendLedEntry."Remaining Amount", 0.01, '='))
                                else begin
                                    if vendLedEntry."To be Paid" > Abs(vendLedEntry."Remaining Amount") then
                                        Error('To be Paid Must be Less than or equal to Remaining Amount! Doc No:- %1', vendLedEntry."Document No.");
                                    GenEvent.CheckPOPayment(vendLedEntry."Reference Document No.", ROUND(ABS(vendLedEntry."To be Paid"), 0.01, '='));
                                end;
                                //RKS290126+
 
                                WorkflowEvent.OnSendVendorPaymentForApproval(vendLedEntry);
                            until vendLedEntry.Next() = 0;
                    end;
                end;
            }
            action(CancelApprovalRequest)
            {
                ApplicationArea = all;
                Caption = 'Cancel Approval Re&quest';
                Image = Cancel;
                Promoted = true;
                Visible = calforsendap;
                PromotedCategory = Process;
                PromotedIsBig = true;
                ToolTip = 'Executes the Cancel Approval Re&quest action.';
 
                trigger OnAction()
                var
                    WorkflowEvent: Codeunit "Workflow Events";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            WorkflowEvent.OnCancelVendorPaymentForApproval(vendLedEntry);
                        until vendLedEntry.Next() = 0;
                    //WorkflowEvent.OnCancelVendorPaymentForApproval(Rec);
                end;
            }
            action(Approve)
            {
                ApplicationArea = all;
                Caption = 'Approve';
                Image = Approve;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'Approve the requested changes.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            ApprovalsMgmt.ApproveRecordApprovalRequest(vendLedEntry.RecordId);
                        until vendLedEntry.Next() = 0;
                end;
            }
            action(Reject)
            {
                ApplicationArea = all;
                Caption = 'Reject';
                Image = Approve;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'Reject the requested changes.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            ApprovalsMgmt.RejectRecordApprovalRequest(vendLedEntry.RecordId);
                        until vendLedEntry.Next() = 0;
                end;
            }
            action(Comments)
            {
                ApplicationArea = All;
                Caption = 'Comments';
                Image = ViewComments;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'View or add comments for the record.';
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    RecRef: RecordRef;
                    AppEntry: Record "Approval Entry";
                begin
                    AppEntry.Reset();
                    AppEntry.SetRange("Table ID", 25);
                    AppEntry.SetRange("Record ID to Approve", Rec.RecordID);
                    AppEntry.SetRange(Status, AppEntry.Status::Open);
                    AppEntry.SetRange("Approver ID", UserId);
                    AppEntry.SetRange("Related to Change", false);
                    if AppEntry.FindFirst() then begin
                        RecRef.Get(AppEntry."Record ID to Approve");
                        Clear(ApprovalsMgmt);
                        ApprovalsMgmt.GetApprovalCommentForWorkflowStepInstanceID(RecRef, AppEntry."Workflow Step Instance ID");
                    end;
                end;
            }
            action(Approvals)
            {
                AccessByPermission = TableData "Approval Entry" = R;
                ApplicationArea = Suite;
                Caption = 'Approvals';
                Image = Approvals;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                //Visible = calforApprove;
                ToolTip = 'View a list of the records that are waiting to be approved. For example, you can see who requested the record to be approved, when it was sent, and when it is due to be approved.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                begin
                    ApprovalsMgmt.OpenApprovalEntriesPage(Rec.RecordId);
                end;
            }
 
            action("Create Bank Payment Voucher")
            {
                ApplicationArea = all;
                Caption = 'Create Bank Payment Voucher';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    GenJournalLine: Record "Gen. Journal Line";
                    GenJournalTemplate: Record "Gen. Journal Template";
                    GenJournalBatch: Record "Gen. Journal Batch";
                    // PurchaseHeader: Record "Purchase Header";
                    PurchasesPayablesSetup: Record "Purchases & Payables Setup";
                    DocumentNo: Code[20];
                    NoSeriesBatch: Codeunit "No. Series - Batch";
                    LineNo: Integer;
                    BankPaymentVoucher: Page "Bank Payment Voucher";
                    PurchaseLine: Record "Purchase Line";
                    VLE: Record "Vendor Ledger Entry";
                    VLE1: Record "Vendor Ledger Entry";
                    PPI: Record "Purch. Inv. Header";
                    OrderAddress: Record "Order Address";
                    VendorBankAccount: Record "Vendor Bank Account";
                    Vendor: Record Vendor;
                    NatureOfVendor: Record "Nature Of Vendor";
                    GenEvent: Codeunit "General Events";
                    TDSCode: code[10];
                    CentreCode: code[20];
                begin
 
                    IF CONFIRM('Do you want to create payment Entries for Selected Lines') THEN BEGIN
                        DocumentNo := '';
                        PurchasesPayablesSetup.GET;
                        GenJournalTemplate.GET('BANK PAYM');
                        GenJournalBatch.GET('BANK PAYM', Rec."Global Dimension 2 Code" + '-' + 'BP');
                        GenJournalBatch.TESTFIELD("No. Series");
                        GenJournalBatch.TESTFIELD("Posting No. Series");
                        LineNo := 0;
                        GenJournalLine.RESET;
                        GenJournalLine.SETRANGE("Journal Template Name", 'BANK PAYM');
                        GenJournalLine.SETRANGE("Journal Batch Name", Rec."Global Dimension 2 Code" + '-' + 'BP');
                        IF GenJournalLine.FINDLAST THEN begin
                            LineNo := GenJournalLine."Line No.";
                            DocumentNo := GenJournalLine."Document No.";
                        end;
 
                        Clear(CentreCode);
                        CurrPage.SetSelectionFilter(VLE1);
                        if VLE1.FindFirst() then
                            repeat
                                if CentreCode <> '' then begin
                                    if CentreCode <> VLE1."Global Dimension 2 Code" then
                                        Error('Please select only one centre.');
                                end;
                                CentreCode := VLE1."Global Dimension 2 Code";
                            until VLE1.Next() = 0;
 
                        if DocumentNo = '' then
                            //DocumentNo := NoSeries.GetNextNo(GenJournalBatch."No. Series", TODAY, false)
                            DocumentNo := NoSeriesBatch.PeekNextNo(GenJournalBatch."No. Series", TODAY)
                        else
                            DocumentNo := IncStr(DocumentNo);
 
                        CurrPage.SetSelectionFilter(VLE);
                        if VLE.FindFirst() then
                            repeat
                                VLE.CalcFields("Payment Entry Created", "Remaining Amount");
                                VLE.TestField("Payment Entry Created", false);
                                VLE.TestField("Payment On Hold", false);
                                //RKS030326-
                                if VLE.Department <> 'SP ELECTRICAL' then
                                    if VLE."Due Date" > Today then
                                        Error('Due Date Must be Less Than Today for Doc. %1', VLE."Document No.");
                                //RKS030326+
                                if VLE."To be Paid" = 0 then
                                    GenEvent.CheckPOPayment(VLE."Reference Document No.", -1 * ROUND(VLE."Remaining Amount", 0.01, '='))
                                else begin
                                    if VLE."To be Paid" > Abs(VLE."Remaining Amount") then
                                        Error('To be Paid Must be Less than or equal to Remaining Amount! Doc No:- %1', VLE."Document No.");
                                    GenEvent.CheckPOPayment(VLE."Reference Document No.", ROUND(ABS(VLE."To be Paid"), 0.01, '='));
                                end;
                                GenJournalLine.INIT;
                                GenJournalLine."Journal Template Name" := 'BANK PAYM';
                                GenJournalLine."Journal Batch Name" := VLE."Global Dimension 2 Code" + '-' + 'BP';
                                GenJournalLine."Document No." := DocumentNo;
                                GenJournalLine."Line No." := LineNo + 10000;
                                GenJournalLine.VALIDATE("Posting Date", TODAY);
                                GenJournalLine.VALIDATE("Document Date", TODAY);
                                GenJournalLine.VALIDATE("Document Type", GenJournalLine."Document Type"::Payment);
                                GenJournalLine."Document No." := DocumentNo;
                                GenJournalLine.VALIDATE("Party Type", GenJournalLine."Party Type"::Vendor);
                                GenJournalLine.VALIDATE("Party Code", VLE."Vendor No.");
                                if VLE."To be Paid" = 0 then
                                    GenJournalLine.VALIDATE(Amount, -1 * ROUND(VLE."Remaining Amount", 0.01, '='))
                                else
                                    GenJournalLine.VALIDATE(Amount, ROUND(ABS(VLE."To be Paid"), 0.01, '='));
                                GenJournalLine."Source Code" := 'BANKPYMTV';
                                GenJournalLine."Bill-to/Pay-to No." := VLE."Vendor No.";
                                GenJournalLine."External Document Date" := TODAY;
                                GenJournalLine."Ref. Document Type" := GenJournalLine."Ref. Document Type"::Order;
                                GenJournalLine."Reference Document No." := VLE."Reference Document No.";
                                GenJournalLine."Responsibility Center" := VLE."Responsibility Center";  // ALLE AKUL ADD 080224
                                GenJournalLine."Posting Type" := GenJournalLine."Posting Type"::Running;  // ALLE AKUL ADD 080224
                                GenJournalLine.VALIDATE("Bal. Account Type", GenJournalLine."Bal. Account Type"::"Bank Account");
                                IF GenJournalTemplate."Bal. Account Type" = GenJournalTemplate."Bal. Account Type"::"Bank Account" THEN
                                    GenJournalLine.VALIDATE("Bal. Account No.", GenJournalTemplate."Bal. Account No.");
                                GenJournalLine."Transaction Type" := GenJournalLine."Transaction Type"::Purchase;
                                GenJournalLine."Initiator User ID" := USERID;
                                GenJournalLine.VALIDATE("Shortcut Dimension 1 Code", Rec."Global Dimension 1 Code");
                                GenJournalLine."Posting No. Series" := GenJournalBatch."Posting No. Series";
                                GenJournalLine."Shortcut Dimension 2 Code" := VLE."Global Dimension 2 Code";
                                GenJournalLine.Validate("Applies-to Doc. Type", GenJournalLine."Applies-to Doc. Type"::Invoice);
                                //GenJournalLine.Validate("Applies-to Doc. No.", VLE."Document No.");
                                GenJournalLine."Applies-to Doc. No." := VLE."Document No.";
                                GenJournalLine."VLE No." := VLE."Entry No.";
                                GenJournalLine."Auto Payment" := true;
                                GenJournalLine.INSERT;
                                LineNo := GenJournalLine."Line No.";
                                GenJournalLine.VALIDATE("Ref. Job No.");
                                GenJournalLine.VALIDATE("Posting Type");
                                GenJournalLine.Validate("Location Code", VLE."Location Code");
                                //RKS231025-
                                Vendor.Reset();
                                Vendor.get(VLE."Vendor No.");
                                if Vendor."Nature Of Vendor" <> '' then begin
                                    NatureOfVendor.Reset();
                                    NatureOfVendor.Get(Vendor."Nature Of Vendor");
                                    if NatureOfVendor."Allow BankAcc Order Address" then begin
                                        PPI.Reset();
                                        PPI.SetRange("No.", VLE."Document No.");
                                        if PPI.FindFirst() then begin
                                            if PPI."Order Address Code" <> '' then begin
                                                VendorBankAccount.Reset();
                                                VendorBankAccount.SetRange("Vendor No.", VLE."Vendor No.");
                                                VendorBankAccount.SetRange("Order Address Code", PPI."Order Address Code");
                                                if VendorBankAccount.FindFirst() then
                                                    GenJournalLine."Recipient Bank Account" := VendorBankAccount.Code;
                                            end;
                                        end;
                                    end;
                                end;
                                //RKS231025+
                                GenJournalLine.MODIFY;
                                DocumentNo := IncStr(DocumentNo);
                            until VLE.Next() = 0;
                    END ELSE
                        MESSAGE('Cancelled By User');
 
                end;
            }
            action("Bank Payment Voucher")
            {
                ApplicationArea = all;
                Caption = 'Bank Payment Voucher';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                RunObject = page "Bank Payment Voucher";
            }
            action("MarkHold")
            {
                ApplicationArea = all;
                Caption = 'Mark Hold';
                Visible = ShowButton;//ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE."Payment On Hold" := true;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
            }
            action("MarkUnHold")
            {
                ApplicationArea = all;
                Caption = 'Mark UnHold';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE."Payment On Hold" := false;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
 
            }
            action("RejectPayment")
            {
                ApplicationArea = all;
                Caption = 'Reject Payment';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE.TestField("Payment Rejection Comment");
                            VLE."Approval Status" := VLE."Approval Status"::Open;
                            VLE."Payment Rejected" := false;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                    CurrPage.Update();
                end;
 
            }
            action("RejectionComment")
            {
                ApplicationArea = all;
                Caption = 'Input Rejection Comment';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                    InpComPage: page "Input Payment Rejec. Comment";
                    RejComent: text[100];
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            Clear(RejComent);
                            Clear(InpComPage);
                            InpComPage.RunModal();
                            InpComPage.GetComment(RejComent);
 
                            if RejComent = '' then
                                Error('Please Input Rejction Comment!');
                            VLE."Payment Rejection Comment" := RejComent;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
 
            }
            action("UpdateDepartment")
            {
                ApplicationArea = all;
                Caption = 'Update Department/ItemCate';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    PurOrd: Record "Purchase Header";
                    PurchInvHead: Record "Purch. Inv. Header";
                    VlE: Record "Vendor Ledger Entry";
                begin
                    VlE.Reset();
                    VlE.SetRange("Document Type", VlE."Document Type"::Invoice);
                    VlE.SetRange(Department, '');
                    if VlE.FindSet() then
                        repeat
                            PurchInvHead.Reset();
                            PurchInvHead.SetRange("No.", VlE."Document No.");
                            if PurchInvHead.FindFirst() then begin
                                PurOrd.Reset();
                                PurOrd.SetRange("No.", PurchInvHead."Order No.");
                                if PurOrd.FindFirst() then begin
                                    VlE.Department := PurOrd."Department";
                                    VlE.Modify();
                                end;
                            end;
                        until VlE.Next() = 0;
 
                    VlE.Reset();
                    VlE.SetRange("Document Type", VlE."Document Type"::Invoice);
                    VlE.SetRange(VlE."Item Category Code", '');
                    if VlE.FindSet() then
                        repeat
                            PurchInvHead.Reset();
                            PurchInvHead.SetRange("No.", VlE."Document No.");
                            if PurchInvHead.FindFirst() then begin
                                PurOrd.Reset();
                                PurOrd.SetRange("No.", PurchInvHead."Order No.");
                                if PurOrd.FindFirst() then begin
                                    VlE."Item Category Code" := PurOrd."Item Category Code";
                                    VlE.Modify();
                                end;
                            end;
                        until VlE.Next() = 0;
                    Message('Updated!');
 
                end;
            }
            action("UpdateSender")
            {
                ApplicationArea = all;
                Caption = 'Update Sender ID';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VlE: Record "Vendor Ledger Entry";
                    PTLP: Record "Payment Terms Line Purchase";
                    ApproEntry: Record "Approval Entry";
                    RecRef: RecordRef;
                    Variant: Variant;
                begin
                    ApproEntry.Reset();
                    //ApproEntry.SetRange("Approver ID", USERID);
                    ApproEntry.SetFilter("Table ID", '%1|%2', Database::"Vendor Ledger Entry", Database::"Payment Terms Line Purchase");
                    ApproEntry.SetRange("Status", ApproEntry.Status::Open);
                    ApproEntry.SetRange("Related to Change", false);
                    if ApproEntry.FindSet() then begin
                        repeat
                            if RecRef.Get(ApproEntry."Record ID to Approve") then begin
                                case ApproEntry."Table ID" of
                                    database::"Vendor Ledger Entry":
                                        begin
                                            Variant := RecRef;
                                            VlE := Variant;
                                            VlE."Sender ID" := ApproEntry."Sender ID";
                                            VlE.Modify();
                                        end;
                                    database::"Payment Terms Line Purchase":
                                        begin
                                            Variant := RecRef;
                                            PTLP := Variant;
                                            PTLP."Sender ID" := ApproEntry."Sender ID";
                                            PTLP.Modify();
                                        end;
                                end;
                            end;
                        until ApproEntry.Next() = 0;
                    end;
                end;
            }
            //
            action("UpdateOrderNo")
            {
                ApplicationArea = all;
                Caption = 'Update OrderNo Payment Term Line Purch.';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    PaymentTermLinePurch: Record "Payment Terms Line Purchase";
                begin
                    PaymentTermLinePurch.Reset();
                    PaymentTermLinePurch.SetRange("Table ID", 38);
                    PaymentTermLinePurch.SetRange("Transaction Type", PaymentTermLinePurch."Transaction Type"::Purchase);
                    PaymentTermLinePurch.SetRange("Document Type", PaymentTermLinePurch."Document Type"::Order);
                    PaymentTermLinePurch.SetRange("Main Payment Type", PaymentTermLinePurch."Main Payment Type"::Advance);
                    PaymentTermLinePurch.SetRange(Status, PaymentTermLinePurch.Status::Released);
                    if PaymentTermLinePurch.FindSet() then
                        repeat
                            PaymentTermLinePurch."Order No." := PaymentTermLinePurch."Document No.";
                            PaymentTermLinePurch.Modify();
                        until PaymentTermLinePurch.Next() = 0;
                    Message('Updated!');
                end;
            }
            //temp
            action(UpdateFloorcode)
            {
                ApplicationArea = all;
                Caption = 'Update Floor code ILE';
                Image = UpdateDescription;
                Promoted = true;
                PromotedCategory = Process;
                Visible = isVisble;
                trigger OnAction()
                var
                    ILE: Record "Item Ledger Entry";
                    GPH: Record "Gate Pass Header";
                begin
                    GPH.Reset();
                    GPH.SetRange("Document Type", GPH."Document Type"::MIN);
                    GPH.SetRange(Status, GPH.Status::Close);
                    GPH.SetFilter("Floor Code", '<>%1', '');
                    if GPH.FindSet() then
                        repeat
                            ILE.Reset();
                            ILE.SetRange("Document No.", GPH."Document No.");
                            if ILE.FindSet() then
                                repeat
                                    ILE."Floor Code" := GPH."Floor Code";
                                    ILE."Floor Name" := GPH."Floor Name";
                                    ILE.Modify();
                                until ILE.Next() = 0;
                        until GPH.Next() = 0;
                    Message('Updated!');
                end;
            }
        }
    }
 
    trigger OnOpenPage()
    var
        UserSetup: Record "User Setup";
    begin
        UserSetup.Get(UserId);
        Rec.FilterGroup(2);
        if not UserSetup."Access to All Department" then begin
            if UserSetup."Department Filter" <> '' then
                //Rec.SetFilter("Shortcut Dimension 5 Code", UserSetup."Department Filter")
                Rec.SetFilter(Department, UserSetup."Department Filter")
            else
                //Rec.SetRange("Shortcut Dimension 5 Code", UserSetup.Department);
                Rec.SetRange(Department, UserSetup.Department);
        end;
        Rec.FilterGroup(0);
 
        UserSetup.Get(UserId);
        if UserSetup."Create Advance Bank Payment" then
            ShowButton := true
        else
            ShowButton := false;
 
        if (calfromBankPay) and (ShowButton) then
            ShowButton := true
        else
            ShowButton := false;
 
        //temp
        if UserId in ['GAURAV.CHOUDHARY', 'MONU.MISHRA', 'ANKIT.AGARWAL', 'SW_D365_BC'] then
            isVisble := true;
 
        if UserSetup."AllowEdit DueDate onVend.Paymt" then
            IsEditable := true
        else
            IsEditable := false;
 
    end;
 
    trigger OnAfterGetRecord()
    var
    //PurOrd: Record "Purch. Inv. Header";
 
    begin
        // PurOrd.SetRange("No.", Rec."Document No.");
        // if PurOrd.FindFirst() then
        //     Rec."Shortcut Dimension 5 Code" := PurOrd."Department";
 
        PH.Reset();
        PH.SetRange("No.", Rec."Reference Document No.");
        if PH.FindFirst() then begin
            PORemarks := PH.Remarks;
            ItemCategory := PH."Item Category Code";
        end else begin
            PORemarks := '';
            ItemCategory := '';
        end;
 
        if Job.Get(Rec."Global Dimension 1 Code") then
            ProjectName := Job.Description
        else
            ProjectName := '';
 
        // if Rec."To be Paid" = 0 then
        //     Rec."To be Paid" := abs(Rec."Remaining Amount");//RKS150725
 
        if Rec."Approval Status" = Rec."Approval Status"::Open then begin
            Rec."To be Paid" := abs(Rec."Remaining Amount");
        end else begin
            if Rec."To be Paid" = 0 then
                Rec."To be Paid" := abs(Rec."Remaining Amount");//RKS150725
        end;
 
    end;
 
    procedure CalformApprove(calApp: Boolean)
    begin
        calforApprove := calApp;
    end;
 
    procedure CalforSendApp(Calsend: Boolean)
    begin
        calforsendap := Calsend;
    end;
 
    procedure CalforBankPay(BankPay: Boolean)
    begin
        calfromBankPay := BankPay;
    end;
 
    var
        PH: Record "Purchase Header";
        Job: Record Job;
        PORemarks: Text;
        ItemCategory: code[20];
        ProjectName: Text[500];
        ApprovalEntry: Record "Approval Entry";
        calforApprove: Boolean;
        calforsendap: Boolean;
        calfromBankPay: Boolean;
        ShowButton: Boolean;
        isVisble: Boolean;
        IsEditable: Boolean;
 
}


Here is the pageExtension as i have read only access to source page 
page 50153 "Vendor Payment"
{
    PageType = List;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = "Vendor Ledger Entry";
    SourceTableView = where("Document Type" = const(Invoice), "Remaining Amount" = filter(< 0), "Vendor Posting Group" = filter(<> 'BRANCH'));
    InsertAllowed = false;
    DeleteAllowed = false;
    Permissions = tabledata "Vendor Ledger Entry" = M, tabledata "Payment Terms Line Purchase" = M, tabledata "Item Ledger Entry" = RM;
    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field("Posting Date"; Rec."Posting Date")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Document Date"; Rec."Document Date")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Due Date"; Rec."Due Date")
                {
                    ApplicationArea = All;
                    Editable = IsEditable;
                }
                field("Prepayment Due Date"; Rec."Prepayment Due Date")
                {
                    ApplicationArea = all;
                    Caption = 'Prepayment Due Date';
                    Editable = false;
                }
 
                field("Document Type"; Rec."Document Type")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Document No."; Rec."Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Approval Status"; Rec."Approval Status")
                {
                    ApplicationArea = All;
                    Editable = false;
                    Caption = 'Payment Approval';
 
                }
 
                field("Sender ID"; Rec."Sender ID")
                {
                    ApplicationArea = all;
                    Editable = false;
                    Visible = calforApprove;
                }
                field("Approver ID"; Rec."Approver ID")
                {
                    ApplicationArea = all;
                    Editable = false;
                    //Visible = calforApprove;
                }
 
                // field("Item Category"; ItemCategory)
                // {
                //     ApplicationArea = all;
                //     Editable = false;
                // }
                field("Item Category Code"; Rec."Item Category Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("External Document No."; Rec."External Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Reference Document No."; Rec."Reference Document No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Vendor No."; Rec."Vendor No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Vendor Name"; Rec."Vendor Name")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Global Dimension 2 Code"; Rec."Global Dimension 2 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Global Dimension 1 Code"; Rec."Global Dimension 1 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Project Name"; ProjectName)
                {
                    ApplicationArea = all;
                    Editable = false;
                }
                field("Shortcut Dimension 3 Code"; Rec."Shortcut Dimension 3 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Shortcut Dimension 4 Code"; Rec."Shortcut Dimension 4 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                // field("Shortcut Dimension 5 Code"; Rec."Shortcut Dimension 5 Code")
                // {
                //     ApplicationArea = All;
                //     Editable = false;
                // }
                field(Department; Rec.Department)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Shortcut Dimension 8 Code"; Rec."Shortcut Dimension 8 Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field(Amount; Rec.Amount)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Remaining Amount"; Rec."Remaining Amount")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("To be Paid"; Rec."To be Paid")
                {
                    ApplicationArea = all;
                    trigger OnValidate()
                    begin
                        if Rec."To be Paid" > Abs(Rec."Remaining Amount") then
                            Error('To be Paid Must be Less than or equal to Remaining Amount!');
                    end;
                }
                field("Payment On Hold"; Rec."Payment On Hold")
                {
                    ApplicationArea = All;
                    Editable = false;//calfromBankPay;
                }
                field("Payment Rejection Comment"; Rec."Payment Rejection Comment")
                {
                    ApplicationArea = All;
                    Editable = false;//calfromBankPay;
                }
                field("Payment Rejected"; Rec."Payment Rejected")
                {
                    ApplicationArea = All;
                    Editable = false;// calfromBankPay;
                    trigger OnValidate()
                    var
                        myInt: Integer;
                    begin
                        if Rec."Payment Rejected" then begin
                            Rec.TestField("Payment Rejection Comment");
                            Rec."Approval Status" := Rec."Approval Status"::Open;
                            Rec."Payment Rejected" := false;
                            CurrPage.Update();
                        end
                        else if Rec."Payment Rejection Comment" <> '' then
                            Error('Payment Rejection Comment Must be Blank!');
                    end;
                }
                field("Entry No."; Rec."Entry No.")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field(Open; Rec.Open)
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Location Code"; Rec."Location Code")
                {
                    ApplicationArea = All;
                    Editable = false;
                }
                field("Payment Entry Created"; Rec."Payment Entry Created")
                {
                    ApplicationArea = all;
                    Editable = false;
                }
                field("PO Remarks"; PORemarks)
                {
                    ApplicationArea = all;
                    Editable = false;
                }
 
            }
        }
        area(Factboxes)
        {
 
        }
    }
 
    actions
    {
        area(Processing)
        {
            action(SendApprovalRequest)
            {
                ApplicationArea = all;
                Caption = 'Send A&pproval Request';
                Image = SendApprovalRequest;
                Visible = calforsendap;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                ToolTip = 'Executes the Send A&pproval Request action.';
                trigger OnAction()
                var
                    WorkflowEvent: Codeunit "Workflow Events";
                    vendLedEntry: Record "Vendor Ledger Entry";
                    GenEvent: Codeunit "General Events";
                begin
                    IF WorkflowEvent.CheckVendorPaymentApprovalsWorkflowEnabled(Rec) THEN begin
                        CurrPage.SetSelectionFilter(vendLedEntry);
                        if vendLedEntry.FindSet() then
                            repeat
                                //RKS290126-
                                vendLedEntry.CalcFields("Remaining Amount");
                                if vendLedEntry."To be Paid" = 0 then
                                    GenEvent.CheckPOPayment(vendLedEntry."Reference Document No.", -1 * ROUND(vendLedEntry."Remaining Amount", 0.01, '='))
                                else begin
                                    if vendLedEntry."To be Paid" > Abs(vendLedEntry."Remaining Amount") then
                                        Error('To be Paid Must be Less than or equal to Remaining Amount! Doc No:- %1', vendLedEntry."Document No.");
                                    GenEvent.CheckPOPayment(vendLedEntry."Reference Document No.", ROUND(ABS(vendLedEntry."To be Paid"), 0.01, '='));
                                end;
                                //RKS290126+
 
                                WorkflowEvent.OnSendVendorPaymentForApproval(vendLedEntry);
                            until vendLedEntry.Next() = 0;
                    end;
                end;
            }
            action(CancelApprovalRequest)
            {
                ApplicationArea = all;
                Caption = 'Cancel Approval Re&quest';
                Image = Cancel;
                Promoted = true;
                Visible = calforsendap;
                PromotedCategory = Process;
                PromotedIsBig = true;
                ToolTip = 'Executes the Cancel Approval Re&quest action.';
 
                trigger OnAction()
                var
                    WorkflowEvent: Codeunit "Workflow Events";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            WorkflowEvent.OnCancelVendorPaymentForApproval(vendLedEntry);
                        until vendLedEntry.Next() = 0;
                    //WorkflowEvent.OnCancelVendorPaymentForApproval(Rec);
                end;
            }
            action(Approve)
            {
                ApplicationArea = all;
                Caption = 'Approve';
                Image = Approve;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'Approve the requested changes.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            ApprovalsMgmt.ApproveRecordApprovalRequest(vendLedEntry.RecordId);
                        until vendLedEntry.Next() = 0;
                end;
            }
            action(Reject)
            {
                ApplicationArea = all;
                Caption = 'Reject';
                Image = Approve;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'Reject the requested changes.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    vendLedEntry: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(vendLedEntry);
                    if vendLedEntry.FindSet() then
                        repeat
                            ApprovalsMgmt.RejectRecordApprovalRequest(vendLedEntry.RecordId);
                        until vendLedEntry.Next() = 0;
                end;
            }
            action(Comments)
            {
                ApplicationArea = All;
                Caption = 'Comments';
                Image = ViewComments;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Visible = calforApprove;
                ToolTip = 'View or add comments for the record.';
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                    RecRef: RecordRef;
                    AppEntry: Record "Approval Entry";
                begin
                    AppEntry.Reset();
                    AppEntry.SetRange("Table ID", 25);
                    AppEntry.SetRange("Record ID to Approve", Rec.RecordID);
                    AppEntry.SetRange(Status, AppEntry.Status::Open);
                    AppEntry.SetRange("Approver ID", UserId);
                    AppEntry.SetRange("Related to Change", false);
                    if AppEntry.FindFirst() then begin
                        RecRef.Get(AppEntry."Record ID to Approve");
                        Clear(ApprovalsMgmt);
                        ApprovalsMgmt.GetApprovalCommentForWorkflowStepInstanceID(RecRef, AppEntry."Workflow Step Instance ID");
                    end;
                end;
            }
            action(Approvals)
            {
                AccessByPermission = TableData "Approval Entry" = R;
                ApplicationArea = Suite;
                Caption = 'Approvals';
                Image = Approvals;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                //Visible = calforApprove;
                ToolTip = 'View a list of the records that are waiting to be approved. For example, you can see who requested the record to be approved, when it was sent, and when it is due to be approved.';
 
                trigger OnAction()
                var
                    ApprovalsMgmt: Codeunit "Approvals Mgmt.";
                begin
                    ApprovalsMgmt.OpenApprovalEntriesPage(Rec.RecordId);
                end;
            }
 
            action("Create Bank Payment Voucher")
            {
                ApplicationArea = all;
                Caption = 'Create Bank Payment Voucher';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    GenJournalLine: Record "Gen. Journal Line";
                    GenJournalTemplate: Record "Gen. Journal Template";
                    GenJournalBatch: Record "Gen. Journal Batch";
                    // PurchaseHeader: Record "Purchase Header";
                    PurchasesPayablesSetup: Record "Purchases & Payables Setup";
                    DocumentNo: Code[20];
                    NoSeriesBatch: Codeunit "No. Series - Batch";
                    LineNo: Integer;
                    BankPaymentVoucher: Page "Bank Payment Voucher";
                    PurchaseLine: Record "Purchase Line";
                    VLE: Record "Vendor Ledger Entry";
                    VLE1: Record "Vendor Ledger Entry";
                    PPI: Record "Purch. Inv. Header";
                    OrderAddress: Record "Order Address";
                    VendorBankAccount: Record "Vendor Bank Account";
                    Vendor: Record Vendor;
                    NatureOfVendor: Record "Nature Of Vendor";
                    GenEvent: Codeunit "General Events";
                    TDSCode: code[10];
                    CentreCode: code[20];
                begin
 
                    IF CONFIRM('Do you want to create payment Entries for Selected Lines') THEN BEGIN
                        DocumentNo := '';
                        PurchasesPayablesSetup.GET;
                        GenJournalTemplate.GET('BANK PAYM');
                        GenJournalBatch.GET('BANK PAYM', Rec."Global Dimension 2 Code" + '-' + 'BP');
                        GenJournalBatch.TESTFIELD("No. Series");
                        GenJournalBatch.TESTFIELD("Posting No. Series");
                        LineNo := 0;
                        GenJournalLine.RESET;
                        GenJournalLine.SETRANGE("Journal Template Name", 'BANK PAYM');
                        GenJournalLine.SETRANGE("Journal Batch Name", Rec."Global Dimension 2 Code" + '-' + 'BP');
                        IF GenJournalLine.FINDLAST THEN begin
                            LineNo := GenJournalLine."Line No.";
                            DocumentNo := GenJournalLine."Document No.";
                        end;
 
                        Clear(CentreCode);
                        CurrPage.SetSelectionFilter(VLE1);
                        if VLE1.FindFirst() then
                            repeat
                                if CentreCode <> '' then begin
                                    if CentreCode <> VLE1."Global Dimension 2 Code" then
                                        Error('Please select only one centre.');
                                end;
                                CentreCode := VLE1."Global Dimension 2 Code";
                            until VLE1.Next() = 0;
 
                        if DocumentNo = '' then
                            //DocumentNo := NoSeries.GetNextNo(GenJournalBatch."No. Series", TODAY, false)
                            DocumentNo := NoSeriesBatch.PeekNextNo(GenJournalBatch."No. Series", TODAY)
                        else
                            DocumentNo := IncStr(DocumentNo);
 
                        CurrPage.SetSelectionFilter(VLE);
                        if VLE.FindFirst() then
                            repeat
                                VLE.CalcFields("Payment Entry Created", "Remaining Amount");
                                VLE.TestField("Payment Entry Created", false);
                                VLE.TestField("Payment On Hold", false);
                                //RKS030326-
                                if VLE.Department <> 'SP ELECTRICAL' then
                                    if VLE."Due Date" > Today then
                                        Error('Due Date Must be Less Than Today for Doc. %1', VLE."Document No.");
                                //RKS030326+
                                if VLE."To be Paid" = 0 then
                                    GenEvent.CheckPOPayment(VLE."Reference Document No.", -1 * ROUND(VLE."Remaining Amount", 0.01, '='))
                                else begin
                                    if VLE."To be Paid" > Abs(VLE."Remaining Amount") then
                                        Error('To be Paid Must be Less than or equal to Remaining Amount! Doc No:- %1', VLE."Document No.");
                                    GenEvent.CheckPOPayment(VLE."Reference Document No.", ROUND(ABS(VLE."To be Paid"), 0.01, '='));
                                end;
                                GenJournalLine.INIT;
                                GenJournalLine."Journal Template Name" := 'BANK PAYM';
                                GenJournalLine."Journal Batch Name" := VLE."Global Dimension 2 Code" + '-' + 'BP';
                                GenJournalLine."Document No." := DocumentNo;
                                GenJournalLine."Line No." := LineNo + 10000;
                                GenJournalLine.VALIDATE("Posting Date", TODAY);
                                GenJournalLine.VALIDATE("Document Date", TODAY);
                                GenJournalLine.VALIDATE("Document Type", GenJournalLine."Document Type"::Payment);
                                GenJournalLine."Document No." := DocumentNo;
                                GenJournalLine.VALIDATE("Party Type", GenJournalLine."Party Type"::Vendor);
                                GenJournalLine.VALIDATE("Party Code", VLE."Vendor No.");
                                if VLE."To be Paid" = 0 then
                                    GenJournalLine.VALIDATE(Amount, -1 * ROUND(VLE."Remaining Amount", 0.01, '='))
                                else
                                    GenJournalLine.VALIDATE(Amount, ROUND(ABS(VLE."To be Paid"), 0.01, '='));
                                GenJournalLine."Source Code" := 'BANKPYMTV';
                                GenJournalLine."Bill-to/Pay-to No." := VLE."Vendor No.";
                                GenJournalLine."External Document Date" := TODAY;
                                GenJournalLine."Ref. Document Type" := GenJournalLine."Ref. Document Type"::Order;
                                GenJournalLine."Reference Document No." := VLE."Reference Document No.";
                                GenJournalLine."Responsibility Center" := VLE."Responsibility Center";  // ALLE AKUL ADD 080224
                                GenJournalLine."Posting Type" := GenJournalLine."Posting Type"::Running;  // ALLE AKUL ADD 080224
                                GenJournalLine.VALIDATE("Bal. Account Type", GenJournalLine."Bal. Account Type"::"Bank Account");
                                IF GenJournalTemplate."Bal. Account Type" = GenJournalTemplate."Bal. Account Type"::"Bank Account" THEN
                                    GenJournalLine.VALIDATE("Bal. Account No.", GenJournalTemplate."Bal. Account No.");
                                GenJournalLine."Transaction Type" := GenJournalLine."Transaction Type"::Purchase;
                                GenJournalLine."Initiator User ID" := USERID;
                                GenJournalLine.VALIDATE("Shortcut Dimension 1 Code", Rec."Global Dimension 1 Code");
                                GenJournalLine."Posting No. Series" := GenJournalBatch."Posting No. Series";
                                GenJournalLine."Shortcut Dimension 2 Code" := VLE."Global Dimension 2 Code";
                                GenJournalLine.Validate("Applies-to Doc. Type", GenJournalLine."Applies-to Doc. Type"::Invoice);
                                //GenJournalLine.Validate("Applies-to Doc. No.", VLE."Document No.");
                                GenJournalLine."Applies-to Doc. No." := VLE."Document No.";
                                GenJournalLine."VLE No." := VLE."Entry No.";
                                GenJournalLine."Auto Payment" := true;
                                GenJournalLine.INSERT;
                                LineNo := GenJournalLine."Line No.";
                                GenJournalLine.VALIDATE("Ref. Job No.");
                                GenJournalLine.VALIDATE("Posting Type");
                                GenJournalLine.Validate("Location Code", VLE."Location Code");
                                //RKS231025-
                                Vendor.Reset();
                                Vendor.get(VLE."Vendor No.");
                                if Vendor."Nature Of Vendor" <> '' then begin
                                    NatureOfVendor.Reset();
                                    NatureOfVendor.Get(Vendor."Nature Of Vendor");
                                    if NatureOfVendor."Allow BankAcc Order Address" then begin
                                        PPI.Reset();
                                        PPI.SetRange("No.", VLE."Document No.");
                                        if PPI.FindFirst() then begin
                                            if PPI."Order Address Code" <> '' then begin
                                                VendorBankAccount.Reset();
                                                VendorBankAccount.SetRange("Vendor No.", VLE."Vendor No.");
                                                VendorBankAccount.SetRange("Order Address Code", PPI."Order Address Code");
                                                if VendorBankAccount.FindFirst() then
                                                    GenJournalLine."Recipient Bank Account" := VendorBankAccount.Code;
                                            end;
                                        end;
                                    end;
                                end;
                                //RKS231025+
                                GenJournalLine.MODIFY;
                                DocumentNo := IncStr(DocumentNo);
                            until VLE.Next() = 0;
                    END ELSE
                        MESSAGE('Cancelled By User');
 
                end;
            }
            action("Bank Payment Voucher")
            {
                ApplicationArea = all;
                Caption = 'Bank Payment Voucher';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                RunObject = page "Bank Payment Voucher";
            }
            action("MarkHold")
            {
                ApplicationArea = all;
                Caption = 'Mark Hold';
                Visible = ShowButton;//ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE."Payment On Hold" := true;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
            }
            action("MarkUnHold")
            {
                ApplicationArea = all;
                Caption = 'Mark UnHold';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE."Payment On Hold" := false;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
 
            }
            action("RejectPayment")
            {
                ApplicationArea = all;
                Caption = 'Reject Payment';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            VLE.TestField("Payment Rejection Comment");
                            VLE."Approval Status" := VLE."Approval Status"::Open;
                            VLE."Payment Rejected" := false;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                    CurrPage.Update();
                end;
 
            }
            action("RejectionComment")
            {
                ApplicationArea = all;
                Caption = 'Input Rejection Comment';
                Visible = ShowButton;
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VLE: Record "Vendor Ledger Entry";
                    InpComPage: page "Input Payment Rejec. Comment";
                    RejComent: text[100];
                begin
                    CurrPage.SetSelectionFilter(VLE);
                    if VLE.FindFirst() then
                        repeat
                            Clear(RejComent);
                            Clear(InpComPage);
                            InpComPage.RunModal();
                            InpComPage.GetComment(RejComent);
 
                            if RejComent = '' then
                                Error('Please Input Rejction Comment!');
                            VLE."Payment Rejection Comment" := RejComent;
                            VLE.Modify(false);
                        until VLE.Next() = 0;
                end;
 
            }
            action("UpdateDepartment")
            {
                ApplicationArea = all;
                Caption = 'Update Department/ItemCate';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    PurOrd: Record "Purchase Header";
                    PurchInvHead: Record "Purch. Inv. Header";
                    VlE: Record "Vendor Ledger Entry";
                begin
                    VlE.Reset();
                    VlE.SetRange("Document Type", VlE."Document Type"::Invoice);
                    VlE.SetRange(Department, '');
                    if VlE.FindSet() then
                        repeat
                            PurchInvHead.Reset();
                            PurchInvHead.SetRange("No.", VlE."Document No.");
                            if PurchInvHead.FindFirst() then begin
                                PurOrd.Reset();
                                PurOrd.SetRange("No.", PurchInvHead."Order No.");
                                if PurOrd.FindFirst() then begin
                                    VlE.Department := PurOrd."Department";
                                    VlE.Modify();
                                end;
                            end;
                        until VlE.Next() = 0;
 
                    VlE.Reset();
                    VlE.SetRange("Document Type", VlE."Document Type"::Invoice);
                    VlE.SetRange(VlE."Item Category Code", '');
                    if VlE.FindSet() then
                        repeat
                            PurchInvHead.Reset();
                            PurchInvHead.SetRange("No.", VlE."Document No.");
                            if PurchInvHead.FindFirst() then begin
                                PurOrd.Reset();
                                PurOrd.SetRange("No.", PurchInvHead."Order No.");
                                if PurOrd.FindFirst() then begin
                                    VlE."Item Category Code" := PurOrd."Item Category Code";
                                    VlE.Modify();
                                end;
                            end;
                        until VlE.Next() = 0;
                    Message('Updated!');
 
                end;
            }
            action("UpdateSender")
            {
                ApplicationArea = all;
                Caption = 'Update Sender ID';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    VlE: Record "Vendor Ledger Entry";
                    PTLP: Record "Payment Terms Line Purchase";
                    ApproEntry: Record "Approval Entry";
                    RecRef: RecordRef;
                    Variant: Variant;
                begin
                    ApproEntry.Reset();
                    //ApproEntry.SetRange("Approver ID", USERID);
                    ApproEntry.SetFilter("Table ID", '%1|%2', Database::"Vendor Ledger Entry", Database::"Payment Terms Line Purchase");
                    ApproEntry.SetRange("Status", ApproEntry.Status::Open);
                    ApproEntry.SetRange("Related to Change", false);
                    if ApproEntry.FindSet() then begin
                        repeat
                            if RecRef.Get(ApproEntry."Record ID to Approve") then begin
                                case ApproEntry."Table ID" of
                                    database::"Vendor Ledger Entry":
                                        begin
                                            Variant := RecRef;
                                            VlE := Variant;
                                            VlE."Sender ID" := ApproEntry."Sender ID";
                                            VlE.Modify();
                                        end;
                                    database::"Payment Terms Line Purchase":
                                        begin
                                            Variant := RecRef;
                                            PTLP := Variant;
                                            PTLP."Sender ID" := ApproEntry."Sender ID";
                                            PTLP.Modify();
                                        end;
                                end;
                            end;
                        until ApproEntry.Next() = 0;
                    end;
                end;
            }
            //
            action("UpdateOrderNo")
            {
                ApplicationArea = all;
                Caption = 'Update OrderNo Payment Term Line Purch.';
                Promoted = true;
                PromotedCategory = Process;
                trigger OnAction()
                var
                    PaymentTermLinePurch: Record "Payment Terms Line Purchase";
                begin
                    PaymentTermLinePurch.Reset();
                    PaymentTermLinePurch.SetRange("Table ID", 38);
                    PaymentTermLinePurch.SetRange("Transaction Type", PaymentTermLinePurch."Transaction Type"::Purchase);
                    PaymentTermLinePurch.SetRange("Document Type", PaymentTermLinePurch."Document Type"::Order);
                    PaymentTermLinePurch.SetRange("Main Payment Type", PaymentTermLinePurch."Main Payment Type"::Advance);
                    PaymentTermLinePurch.SetRange(Status, PaymentTermLinePurch.Status::Released);
                    if PaymentTermLinePurch.FindSet() then
                        repeat
                            PaymentTermLinePurch."Order No." := PaymentTermLinePurch."Document No.";
                            PaymentTermLinePurch.Modify();
                        until PaymentTermLinePurch.Next() = 0;
                    Message('Updated!');
                end;
            }
            //temp
            action(UpdateFloorcode)
            {
                ApplicationArea = all;
                Caption = 'Update Floor code ILE';
                Image = UpdateDescription;
                Promoted = true;
                PromotedCategory = Process;
                Visible = isVisble;
                trigger OnAction()
                var
                    ILE: Record "Item Ledger Entry";
                    GPH: Record "Gate Pass Header";
                begin
                    GPH.Reset();
                    GPH.SetRange("Document Type", GPH."Document Type"::MIN);
                    GPH.SetRange(Status, GPH.Status::Close);
                    GPH.SetFilter("Floor Code", '<>%1', '');
                    if GPH.FindSet() then
                        repeat
                            ILE.Reset();
                            ILE.SetRange("Document No.", GPH."Document No.");
                            if ILE.FindSet() then
                                repeat
                                    ILE."Floor Code" := GPH."Floor Code";
                                    ILE."Floor Name" := GPH."Floor Name";
                                    ILE.Modify();
                                until ILE.Next() = 0;
                        until GPH.Next() = 0;
                    Message('Updated!');
                end;
            }
        }
    }
 
    trigger OnOpenPage()
    var
        UserSetup: Record "User Setup";
    begin
        UserSetup.Get(UserId);
        Rec.FilterGroup(2);
        if not UserSetup."Access to All Department" then begin
            if UserSetup."Department Filter" <> '' then
                //Rec.SetFilter("Shortcut Dimension 5 Code", UserSetup."Department Filter")
                Rec.SetFilter(Department, UserSetup."Department Filter")
            else
                //Rec.SetRange("Shortcut Dimension 5 Code", UserSetup.Department);
                Rec.SetRange(Department, UserSetup.Department);
        end;
        Rec.FilterGroup(0);
 
        UserSetup.Get(UserId);
        if UserSetup."Create Advance Bank Payment" then
            ShowButton := true
        else
            ShowButton := false;
 
        if (calfromBankPay) and (ShowButton) then
            ShowButton := true
        else
            ShowButton := false;
 
        //temp
        if UserId in ['GAURAV.CHOUDHARY', 'MONU.MISHRA', 'ANKIT.AGARWAL', 'SW_D365_BC'] then
            isVisble := true;
 
        if UserSetup."AllowEdit DueDate onVend.Paymt" then
            IsEditable := true
        else
            IsEditable := false;
 
    end;
 
    trigger OnAfterGetRecord()
    var
    //PurOrd: Record "Purch. Inv. Header";
 
    begin
        // PurOrd.SetRange("No.", Rec."Document No.");
        // if PurOrd.FindFirst() then
        //     Rec."Shortcut Dimension 5 Code" := PurOrd."Department";
 
        PH.Reset();
        PH.SetRange("No.", Rec."Reference Document No.");
        if PH.FindFirst() then begin
            PORemarks := PH.Remarks;
            ItemCategory := PH."Item Category Code";
        end else begin
            PORemarks := '';
            ItemCategory := '';
        end;
 
        if Job.Get(Rec."Global Dimension 1 Code") then
            ProjectName := Job.Description
        else
            ProjectName := '';
 
        // if Rec."To be Paid" = 0 then
        //     Rec."To be Paid" := abs(Rec."Remaining Amount");//RKS150725
 
        if Rec."Approval Status" = Rec."Approval Status"::Open then begin
            Rec."To be Paid" := abs(Rec."Remaining Amount");
        end else begin
            if Rec."To be Paid" = 0 then
                Rec."To be Paid" := abs(Rec."Remaining Amount");//RKS150725
        end;
 
    end;
 
    procedure CalformApprove(calApp: Boolean)
    begin
        calforApprove := calApp;
    end;
 
    procedure CalforSendApp(Calsend: Boolean)
    begin
        calforsendap := Calsend;
    end;
 
    procedure CalforBankPay(BankPay: Boolean)
    begin
        calfromBankPay := BankPay;
    end;
 
    var
        PH: Record "Purchase Header";
        Job: Record Job;
        PORemarks: Text;
        ItemCategory: code[20];
        ProjectName: Text[500];
        ApprovalEntry: Record "Approval Entry";
        calforApprove: Boolean;
        calforsendap: Boolean;
        calfromBankPay: Boolean;
        ShowButton: Boolean;
        isVisble: Boolean;
        IsEditable: Boolean;
 
}

page takes approximate 5-10 mins to open
I have the same question (0)
  • Suggested answer
    OussamaSabbouh Profile Picture
    16,186 Super User 2026 Season 1 on at
    Hello,
    The main problem is the page design/performance, not just the number of records. Your Pending Vendor Payment action loops through all matching vendor ledger entries, then for each entry does another lookup in Approval Entry and marks records, so with 1000+ entries it becomes slow very quickly; also in Create Bank Payment for Vendor Payment this line if VendLedEntry.FindSet() then; does nothing useful but still reads the whole filtered dataset before opening the page, so remove it. The second big issue is OnAfterGetRecord() on page Vendor Payment: it runs for every displayed row and does extra lookups to Purchase Header and Job, plus it changes Rec."To be Paid" on the fly; Microsoft recommends keeping OnAfterGetRecord light and avoiding repeated calculations/database work there. Best fix: filter more directly before opening the page, avoid MARKEDONLY logic for approvals if possible, remove unnecessary FindSet, move PO remarks/project name to FlowFields or precomputed fields if possible, use SetAutoCalcFields("Remaining Amount") only where needed, and add proper keys/filter fields on custom fields like Approval Status, Department, Payment Entry Created, etc.
     
    Regards,
    Oussama Sabbouh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,003 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,225 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,192

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans