Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

To make the form button control enable disable using formComboBoxControl

Posted on by 1,457
hi everyone,
 
I was trying to make the form button enable disable on the when i change the valuein form combo box control , i have make the code on event handler of salesquotation form but button is not getting disable ,can any one suggest what mistake i am doing .below is my code .
 
thanks,
Regards,
Dinesh
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To make the form button control enable disable using formComboBoxControl
    hi ,
    everyone ,
    Thanks for helping me out , i will verify the answer soon as the page loading issue gets resolved .
     
     
    thanks,
    Regards,
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 229,993 Most Valuable Professional on at
    To make the form button control enable disable using formComboBoxControl
    I believe this thread is already resolved, Dinesh just said he couldn't verify the answer.
  • Layan Jwei Profile Picture
    Layan Jwei 7,328 Super User 2024 Season 2 on at
    To make the form button control enable disable using formComboBoxControl
    Hi Dinesh,

    I will mention it for the third time, in order for the enable/disable to work when you open the form, then you need to put the code on init method of the form as well .And not just the modified method alone.
     
    So does the code in modified method work now? and did you use coc instead?

    Thanks,
    Layan Jweihan
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    To make the form button control enable disable using formComboBoxControl
    Your question is not clear. You did not mention on which event of form you made this.
     
    I would suggest to use form datasource active and modified method of this field to write a coc.
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,225 Super User 2024 Season 2 on at
    To make the form button control enable disable using formComboBoxControl
     Hi Dinesh,
     
    Try to use selection () instead of selectionchange() method and put your code on init , active and modified field 
     
     
     [FormDataSourceEventHandler(formDataSourceStr(SalesCreateQuotation, SalesQuotationTable), FormDataSourceEventType::Activated)]
     public static void SalesQuotationTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
     {
        FormRun             form = sender.formRun();
        FormDataSource      SalesQuotationTable_ds = form.dataSource(formDataSourceStr(SalesCreateQuotation , SalesQuotationTable)) as      FormDataSource;
        SalesQuotationTable salesQuotationTable    = SalesQuotationTable_ds.cursor();
        FormControl         createRetailCustbtn    = form.design(0).controlName(formcontrolStr(SalesCreateQuotation, DTCreateCustQuotation));
        FormComboBoxControl accountType            = form.design().controlName(formcontrolStr(SalesCreateQuotation, AccountType));
        
        if(accountType.selection() == smmQuotationAccountType::BusRelAccount)
        {
            createRetailCustbtn.enabled(false);
        }
        else if(accountType.selection() == smmQuotationAccountType::CustAccount)
        {
             createRetailCustbtn.enabled(true);
         }
           
      }
  • Martin Dráb Profile Picture
    Martin Dráb 229,993 Most Valuable Professional on at
    To make the form button control enable disable using formComboBoxControl
    Yes, you have to. That's what I said ("... you want to call your code when opening the form, but you don't have any code doing that. Call setFieldsActive() in run(), for example.").
     
    By the way, notice how much simpler it is in comparison with your original code. Please think about what you can learn from this discussion.
     
    For instance, you made a mistake by not taking existing code into account and not focusing on when the code should be executed. You also didn't verify whether your code does what you wanted. You also complicated your life by using event handlers instead of CoC. Quite a few lessons to learn from.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To make the form button control enable disable using formComboBoxControl
    hi ,
    Martin ,
    Can you please repost your previous comment so i can verify it , i can only verify the recent comment , if i try to verify any previous comment the page goes to continueous loading mode.
     
     
    thanks,
    Regards,
    Dinesh
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To make the form button control enable disable using formComboBoxControl
    hi martin ,
    thanks for the code , but i still have to call the method in init other wise when form opens with button enable .
      void init()
        {
            next init();
            this.setFieldsActive();
    
        }
    
        public void setFieldsActive()
        {
            next setFieldsActive();
    
            DTCreateRetailCustQuotation.enabled(!prospect);
        }
    thanks,
    Regards,
    Dinesh
  • Verified answer
    Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To make the form button control enable disable using formComboBoxControl
    hi ,
    martin thanks for reply 
    i have called the code in init method , i will check with your code , the code is working as required thanks for help everyone,
     public void setFieldsActive()
        {
    
           //#define.BTNNAME('DTCreateCustQuotation')
    
            FormControl  createRetailCustbtn = this.design(0).controlName(formcontrolStr(SalesCreateQuotation,DTCreateCustQuotation)) as FormControl;
           FormComboBoxControl    accountType = this.design().controlName(formcontrolStr(SalesCreateQuotation, AccountType)) as FormComboBoxControl ;
          
            if(accountType.selection()  == 0)
            {
             createRetailCustbtn.enabled(false);
            }
            else if(accountType.selection() == 1)
            {
             createRetailCustbtn.enabled(true);
            }
    
            next setFieldsActive();
        }
    
    
        void init()
        {
            next init();
            this.setFieldsActive();
           
        }
     
     
    thanks ,
    Regards,
    Dinesh.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans