Issue with creating a new record when filters are set on a page - Business central

AdrianMAdrianM Member Posts: 1
Hello,
I have noticed a problem in Business Central in that when I want to insert a new record on the page, there is a "reload" and the first record is selected/highlighted instead of a new blank record in which I can put the new values. The problem appears in BC15 and higher when there is a filter set on the date type field. When I click on the new record again, the “reload” doesn’t take place.
This happens when I click "New" action or when I click on the last empty row.
yrmize9rpogw.gif

I have created a simple case where I could test this behavior.
I added new "Date" field to the customer table:
tableextension 5001 "cust Ext" extends Customer
{
    fields
    {
        field(9010; "New Date"; Date)
        {
            Caption = 'New Date';
            DataClassification = ToBeClassified;
            Editable = true;
        }
    }
}

And I have created new page that contains only one action and onOpenPage trigger:
page 5001 "test new rec customer2"
{
    ApplicationArea = All;
    Caption = 'test new rec customer2';
    PageType = List;
    SourceTable = Customer;
    UsageCategory = Lists;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field("No."; Rec."No.")
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the number of the customer. The field is either filled automatically from a defined number series, or you enter the number manually because you have enabled manual number entry in the number-series setup.';
                }
                field("Location Code"; Rec."Location Code")
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies from which location sales to this customer will be processed by default.';
                }
                field(Name; Rec.Name)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the customer''s name.';
                }
                field(Contact; Rec.Contact)
                {
                    ApplicationArea = All;
                    ToolTip = 'Specifies the name of the person you regularly contact when you do business with this customer.';
                }
                field("Currency Code"; Rec."Currency Code")
                {
                    ApplicationArea = All;
                }
                field("New Date"; "New Date")
                {
                    ApplicationArea = All;
                    Editable = true;
                }
            }
        }
    }

    actions
    {
        area(processing)
        {
            action("FilterDate")
            {
                ApplicationArea = All;
                Caption = 'Filter Date';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;

                trigger OnAction()
                begin
                    G_RefDate := CalcDate('<-1M>', G_RefDate);
                    Rec.SetRange("New Date", G_RefDate);
                end;
            }
        }
    }
    trigger OnOpenPage()
    begin
        // Filter Date
        G_RefDate := DMY2Date(6, 10, 2023);
        Rec.SetRange("New Date", G_RefDate); // this makes problem
    end;

    var
        G_RefDate: Date;
}



I have a global data type variable - "G_RefDate" that I use to filter the "New Date" field. On the onOpenPage trigger I set a default value of the G_RefDate and filter records using SetRange. The action decreases G_RefDate by one month and sets the filter again.

I noticed that after removing Rec.SetRange("New Date", G_RefDate); from the trigger, the problem doesn't occur but then I obviously don't have filtered records when I open the page.


Has anyone had a similar problem and know a possible solution? thanks in advance


Sign In or Register to comment.