Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Stop SalesCreateQuotat...
Finance forum
Suggested answer

Stop SalesCreateQuotation form from closing based on dialog output

Posted on by 6
Hi Guys,
 
I have have requirement where when creating a Quotation using the SalesCreateQuotation form, when the OK button is clicked a YesNo dialog should pop-up confirming some details. This YesNo Dialog pops over the SalesCreateQuotation dialog form. If the user clicks Yes, the normal flow should continue, however, if the user clicks No on the YesNo Dialog the SalesCreateQuotation should remain open so the user can correct sales-quotation-header information entered. 
 
Currently I am able to show the YesNo Dialog prompting the user for clarity.
 
Please assist me, How can I stop the SalesCreateQuotation form from proceeding with its normal flow after the user clicks No on the YesNo Dialog ?
  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 6,387 Super User on at
    Stop SalesCreateQuotation form from closing based on dialog output
    I'm afraid the Clicked event handler of the OK button is called after the form's canClose method is called (by the system/kernel/application).
     
    An alternative is to hide the standard OK button and add your own button. The comment below in your code is technically not correct by the way. It's the SalesCreateQuotation form.
     
    //Gets the running SalesEditLines form
     
  • Martin Dráb Profile Picture
    Martin Dráb 225,425 Super User on at
    Stop SalesCreateQuotation form from closing based on dialog output
    Doing it on clicked() method (or the event handler) is a bad idea. You should change the logic executed by the button, not the button itself.
     
    I would have to look into code, but I'm assuming you should extend a validation method of the form letter class.
  • CU20061115-0 Profile Picture
    CU20061115-0 6 on at
    Stop SalesCreateQuotation form from closing based on dialog output
    hi @Anton, I managed to call my dialog within the eventHandler code for the OK button as shown below. Any idea how I can call the canClose() bit ?
     
     
    [FormControlEventHandler(formControlStr(SalesCreateQuotation, OK), FormControlEventType::Clicked)]
        public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            boolean ret = true;
            
    
            Args args = new Args();
            FormCommandButtonControl  callerButton = sender as FormCommandButtonControl;
    
            FormControlEventArgs formControlEventArgs = e as FormControlEventArgs;
    
            DialogButton     diagBut;
            str amountvalue = int2str(25);//pass the total amount value
    
    
            //Retrieves the button that we're reacting to
            FormRun form = callerButton.formRun(); //Gets the running SalesEditLines form
    
            //Get the salesId that was selected in the SalesEditLines form
            FormDataSource salesQuotationTable_ds = form.dataSource(formDataSourceStr(SalesCreateQuotation, SalesQuotationTable )) as FormDataSource;
            SalesQuotationTable salesQuotationTable = salesQuotationTable_ds.cursor();
                   
            
            str strMessage = strfmt("Please confirm Customer Reference '%1' is correct.", salesQuotationTable.CustomerRef);
    
            str strTitle = "Customer Reference Confirmation.";
    
            diagBut = Box::yesNo(strMessage, dialogButton::No, strTitle);
    
            if (diagBut == DialogButton::No)
            {
                ret = checkFailed("Provide the correct Customer Reference to proceed.");
    
                //here is where i need the code to prevent the SalesCreateQuotation from closing
            
            }
            else if(diagBut == DialogButton::Yes)
            {
                ret = true;
            }
            else
            {
                ret = checkFailed("Operation canceled.");
            }       
            
            
        }
    
     
  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 6,387 Super User on at
    Stop SalesCreateQuotation form from closing based on dialog output
    Hi,
     
    The canClose() form method is perfect for this, depending on when this method is called, you can try to override it to stop the form from being closed in certain cases. Usually logic is placed there to allow or prevent the form closing. How / where do you show your dialog prompt?

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,876 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans