Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

How to add trigger to OK and Cancel for StandardDialog Page

Posted on by Microsoft Employee

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
    Community Member Microsoft Employee 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
    Stefano Demiliani 37,152 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
    Divesh 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
    Stefano Demiliani 37,152 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;

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans