Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Access page field's value through Runmodal

(0) ShareShare
ReportReport
Posted on by 358

I am trying to ask a user for a password if it tries to enter unit price below a threshold. 

I do this through a StandardDialog page and trying to write the logic to tackle the Cancel and Ok Button. 

pageextension 50144 MyExtension extends "Sales Order Subform"
{
    layout
    {
        
        modify("Unit Price")
        {
            trigger OnAfterValidate()
            var
                rec_Item: Record Item;
                rec_SalesSetup: Record "Sales & Receivables Setup";
                rec_Set: Record "Sales & Receivables Setup";
                recSO: Record "Sales Line";
            begin
                rec_SalesSetup.Get();
                rec_Item.Get(Rec."No.");
                IF (Rec."Unit Price" < rec_Item."Unit Cost") AND (rec_SalesSetup."Allow Negative Unit Price" = true) then begin
                    Clear(myPage);
                    IF myPage.RunModal() = Action::Cancel then begin
                        rec_Item.Reset();
                        rec_Item.Get(Rec."No.");
                        recSO.SetFilter("Document No.", Rec."Document No.");
                        recso.SetRange("Line No.", Rec."Line No.");
                        recSO.SetFilter("No.", Rec."No.");
                        IF recSO.FindFirst() then begin
                            Rec."Unit Price" := rec_Item."Unit Cost";
                            CurrPage.Update();
                        end;
                    end
                    else
                        IF myPage.RunModal() = Action::Ok then begin
                            rec_Item.Reset();
                            IF Password = rec_Set.Password then
                                CurrPage.Close()

                        end;

                END;
            end;
        }

    var

        myPage: Page Password;

}

Here is the StandardDialog page which has 1) page field that is just a variable. We don't need to store this value hence it is to just check for the password against the Password field I created extending the Sales & Receivable Setup page and table.

page 50140 Password
{
    PageType = StandardDialog;
    ApplicationArea = All;
    UsageCategory = Administration;
    // SourceTable = ;

    layout
    {
        area(Content)
        {

            field(Password; Password)
            {
                ApplicationArea = All;

            }

        }
    }

  

    var
        Password: Text[10];
 
}

 The problem is in the 

  IF myPage.RunModal() Action::Ok then begin 
I can't access the Password page field. How do I access this field's value so my 
 IF myPage.RunModal() = Action::Ok then begin
                            rec_Item.Reset();
                            IF Password = rec_Set.Password then
                            
                                CurrPage.Close()

                        end;
code works. Right now it doesn't recognize Password
  • mysamza Profile Picture
    358 on at
    RE: Access page field's value through Runmodal

    Thanks! rewrote code to accommodate your suggested method and it worked.

  • Verified answer
    Olister Rumao Profile Picture
    3,959 on at
    RE: Access page field's value through Runmodal

    Hi Mesam,

    RunModal is generally used when you want to filter your page based upon some record filter.

    You logic is to open the page which has no source table and then on closing the page and run some logic.

    What you can do is instead of RunModal simple run the page using Page.Run.

    On the password page, you can set the logic on OnQueryClosePage trigger.

    Also, to verify your logic to be applied, you can use as follow as per the example.

    If Confirm ('Do you want to verify password and apply the change?') then begin

    //Your logic.

    end;

    Also, check if your Password field is having ApplicationArea = All;

    Visible = true.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 628 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 495

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 395

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans