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 17
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 18,495 Super User 2024 Season 2 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 228,358 Most Valuable Professional 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.
  • Tapiwa_Louis Profile Picture
    Tapiwa_Louis 17 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 18,495 Super User 2024 Season 2 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?

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,459 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,358 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans