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, ...
Answered

My form's cancelbutton calls the closedOk function

(3) ShareShare
ReportReport
Posted on by 329
I created my own form with two command buttons:  a cancelButton and an OkButton.
 
I added the following logic to my form:
 
 public boolean closedOk()
 {
     DoMyLogic();
     ret = super();
     return ret;
 }
 
Now I noticed that both my Ok and my Cancel buttons call this closedOk method. 
This goes into error and the form is never getting closed.
 
I checked that the form controls match the desired form design:
 
 
 
I tried adding the following method:
 
    [Control("CommandButton")]
    class CancelButton
    {
        public void clicked()
        {
            element.closeCancel();
        }
    }
 
I also tried the same with element.Close(), but still to no avail.
 
I did see that my closedOk is still being called by the FormRunServicesManager.updateLifeCycleStage method.
 
It seems to my the logic does not understand my button is supposed to be a 'cancel'-button, but I would not know why.
Does anyone know why this is happening?
 
 
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at
    What logic do you have in closedOk()? Didn't you actually want to use closeOk() or canClose() instead of closedOk()?
  • Superbunny Profile Picture
    329 on at
    Hey Martin,
     
    In my closedOk function I have a call to a backend class which creates records in multiple tables:
      public boolean closedOk()
      {
          boolean ret;
          copyProductTmp.Property = 'hello';
          FM_CopyProductManager copyProductManager = new FM_CopyProductManager(copyProductTmp);
          copyProductManager.copyProduct();
          ret = super();
          return ret;
      }
     
     
    Didn't you actually want to use closeOk() or canClose() instead of closedOk()?
     
    Currently I am using canClose for formvalidation. (This does not work, as clicking cancel should not validate the form. I realize I should not use canClose for this, but have not found the correct method yet, so that is another problem).
     
    I read the following post:
     
    Based on that I figured closedOk is the correct one. I want the following logic:
     
    -Click ok -> validate the form input and then submit the form aka call my backend logic
    -Click cancel -> do not validate and simply close the form
     
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    I would suggest, you can simply create 2 button 1 Ok button and write the actual logic to perform the CRUD operations and then a Cancel button where you can call element.close(). 
  • Verified answer
    Martin Dráb Profile Picture
    237,803 Most Valuable Professional on at
    It doesn't sound like the correct method to me. The purpose of closedOk() is indicating whether the form was closed with OK. You your code makes unrelated side-effect there and there may be various code checking how the form was closed, therefore your code may be executed multiple times and at moments that you didn't intended.
     
    I think you should use closeOk() instead.
  • Superbunny Profile Picture
    329 on at
    @Martin:
     
    That was it, it works perfectly now, thanks!
     
    @Bharani:
     
    Yes, I could indeed get it working by writing the logic-bindings for the buttons myself,
    but I wanted to get it working by using the standard and not having to write additional code 
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi,

    you said this sentence, but you didn't say what error u got
     
    Now I noticed that both my Ok and my Cancel buttons call this closedOk method. 
    This goes into error and the form is never getting closed.

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 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans