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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to check if dialog button clicked is ok or cancel?

(0) ShareShare
ReportReport
Posted on by 465

So i have a button(Action) when clicked it opens a dialog. 

when i use the event handler when clicking this button, it gets called when i click cancel or ok on the dialog not when i click the button itself.

How can i detect using this event handler if the button clicked is ok or cancel?

i don't want to do the logic on the ok or cancel button of the dialog. because the event handler of ok button gets called before the event handler of the button.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi D365FO user,

    Can you tell if you have a form which will be opened as a dialog or if you build the dialog with x++ coding? Can you share some details about your dialog?

  • D365FO user Profile Picture
    465 on at

    Hi Andre,

    the action menu item opens a form as a dialog (not built using x++). So now when i click the action menu item, it's event handler clicked won't be called unless i click Ok or cancel on the dialog. So on that event handler i want to know if Ok or cancel were clicked

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi,

    Can you not put your code into the "ClosedOk" method of the dialog form? You can do a CoC on this form if it is an out of the box form and extend this method.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi D365FO user,

    Can you elaborate on the business requirement here? Do you need to e.g. refresh the data on the caller form after execution of the dialog?

    It isn't impossible, but challenging. If the action menu item is a button directly on the form without x coding, then the form will be opened independently. You can in this case create a method on the caller form and call this method from the new opened form to tell about the outcome or perform some actions before it really gets closed. When opening the dialog form you then need to fetch the caller form object to be able to achieve this.

    I created a small example myself in the past (AX2012) to update a certain string control on the caller form. On caller form, I had this method: 

    public void updateString(str _string)
    {
        stringVariable = _string;
    
        StringEdit.text(stringVariable);
    }

    On the dialog form you can declare an Object (named callerForm in this example) and fetch the form object.

    public void init()
    {
        super();
    
        callerForm = this.args().caller();
    }
    

    On several places, you can now interact with methods created on the caller form. E.g. on closing the form, I did call the method to update the string control. You can try to achieve the same with coding on the closedOK() method.

    public void close()
    {
        if (callerForm)
        {
            callerForm.updateString(StringEdit.text());
        }
    
        super();
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans