Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Business Central forum

How to add trigger to OK and Cancel for StandardDialog Page

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have cerate a Page and type as StandardDialog. However, I am not sure how to add trigger or write procedure after click OK.

page 50133 TRCShipmentAutomation {

PageType = StandardDialog; Editable = true;

layout {

area(content) {

group(Detail) {

field(OderNoStart; OderNoStart)

{ ApplicationArea = All; Lookup = true; TableRelation = "Sales Header"."No." where ("Document Type" = filter ('Order')); Editable = true; }

field(OrderNoEnd; OrderNoEnd)

{ ApplicationArea = All; Lookup = true; Editable = true; TableRelation = "Sales Header"."No." where ("Document Type" = filter ('Order')); }

field(AutoPack; AutoPack)

{ DrillDown = true; ApplicationArea = All; Editable = true; } } } }

var

OderNoStart: Code[30];

OrderNoEnd: code[30];

AutoPack: Option Yes,No;

}

Categories:
  • Community Member Profile Picture
    on at
    RE: How to add trigger to OK and Cancel for StandardDialog Page

    Thank you so much, your solution works well. Which also give me a lot of new ideas about that. Thank you.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: How to add trigger to OK and Cancel for StandardDialog Page

    I agree with Divesh, I don't know why you've choose to use StandardDialog but if you need to modify records massively when clicking OK, a ProcessingOnly report could the most performant way. If instead you need to execute code, Divesh solution could be the best choice.

  • Verified answer
    Divesh Profile Picture
    327 on at
    RE: How to add trigger to OK and Cancel for StandardDialog Page

    Hi 

    Another solution would be to run the page TRCShipmentAutomation using a custom action and then handle the OK and Cancel.

    Below is the example code:

        actions
        {
            area(Processing)
            {
                action("RunPage")
                {
                    trigger OnAction();
                    var
                        lAction: Action;
                        lPage: Page TRCShipmentAutomation;
                    begin
                        lAction := lPage.RunModal();
                        case lAction of
                            action::OK, action::LookupOK:
                                ExecuteOKCode();
                            action::Cancel, action::LookupCancel:
                                ExecuteCancelCode();
                        end;                  
                    end;
    
                }
            }
        }
    
        procedure ExecuteOKCode();
        begin
        //OK Code Here
        end;
        
        procedure ExecuteCancelCode();
        begin
        //Cancel Code Here
        end;
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: How to add trigger to OK and Cancel for StandardDialog Page

    Never tested with this type of page (I prefer ProcessingOnly reports) but I think you can handle like this:

    trigger OnQueryClosePage(CloseAction : Action) : Boolean;

    var

    begin

     if CloseAction = Action::OK then

       //your code under OK button

     else

       exit(true); //Close the page

    end;

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Featured topics

Product updates

Dynamics 365 release plans