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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Button Event Handler

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

I want to add some code in a button of a form. Its postJournalButton. I want to add the code ONLY if the posted is done succesfully. 

 /// 
    /// 
    /// 
    [FormControlEventHandler(formControlStr(ProdJournalTransProd, PostJournal), FormControlEventType::Clicked)]
    public static void PostJournal_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        
        FormRun         formRun = sender.formRun() as FormRun;
        FormDataSource  prodJournalProd_ds;
        ProdJournalProd prodJournalProd;
   
        
        prodJournalProd_ds  = sender.formRun().dataSource(2);   // form DataSource (el segundo en orden)
        prodJournalProd     = prodJournalProd_ds.cursor();      // Selected record

    IF (JOURNAL POSTED)
        MY CODE HERE
      

How can I achieve this?

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    Moderator on at

    What is your business requirement?

    The event handler is triggered every time when the button is clicked. Why not create an event handler for the posting class/method instead?

  • Suggested answer
    Khushhal Garg Profile Picture
    on at

    Look at method postJournal of class ProdJournalCheckPost and write post event handler on this method. IT should solve your problem

  • Suggested answer
    Sumit Loya Profile Picture
    on at

    Hi Marta,

    The ideal way would be to create CoC of postJournal method instead of button. If your requirement is only for Button, then I would suggest you create an Extension class of PostJournal form control and then create CoC of clicked method. Call the next clicked() first and then write your code. This way you will have all standard code execute and only on successful completion, your code will execute.

  • Suggested answer
    Khushhal Garg Profile Picture
    on at

    Looks like ask is for AX 2012 assuming post is uploaded in AX forum so CoC is not applicable there. CoC (Chain of Command) is in D365FO. If it is for D365FO then CoC can also be used.

  • Suggested answer
    Sumit Loya Profile Picture
    on at

    I highly doubt the request is for AX 2012. The requester has posted code with following syntax for event handler

    [FormControlEventHandler(formControlStr(ProdJournalTransProd, PostJournal), FormControlEventType::Clicked)]

    I don't believe this syntax was possible in AX 2012.

  • Community Member Profile Picture
    on at

    I everyone, thanks for all replies,

    Its D365FO, my requeriment its add some data to a table when the journal is posted (ONLY when the posted was successful) I don't want to modify the standar, only add little bit code.

    Sumit Loya, I will try your suggestion. Thanks a lot.

  • Suggested answer
    nmaenpaa Profile Picture
    Moderator on at

    I suggest hooking into the posting class, not the form button. Otherwise your code will run only when the button is clicked, but not if posting happens in batch or is called from elsewhere.

    Neither approach modifies the standard code, both are extensions. Modifying the standard code is not possible.

  • Goldie Profile Picture
    on at

    Hi Martha,

    Check posting class , you will find place where Info log "Journal posted successfully" or may be some other info log for posting.

    Run COC on this class method and check if Status is Posted and can write your logic there.

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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans