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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to enable disable generate picking list button based on condition

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I want to enable disable generate picking list button based on some condition.

I have tried below code:

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]
    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        SalesTable      salesTable                  = sender.cursor();
        FormDataSource  salesTable_ds               = sender.formRun().dataSource("SalesTable");
        FormRun         element                     = sender.formRun();
        FormControl     buttonUpdatePickingList     = element.design(0).controlName("buttonUpdatePickingList");
       
        if(condition)
        {
            buttonUpdatePickingList.enabled(false);            
        }
        else
        {
            buttonUpdatePickingList.enabled(true);
        }
 

Please suggest the right way 

Thank you

Sona Jee

I have the same question (0)
  • Verified answer
    Sona Jee Profile Picture
    on at
    RE: How to enable disable generate picking list button based on condition

    Hi All,

    I did like this,its worked 

    [ExtensionOf(classStr(SalesTableFormJournalButtonState))]
    final class SalesTables_Extension
    {
        /// 
        /// 
        /// 
        public void applyState()
        {
            SalesTable  salestable = this.parmFormRun().dataSource(tableStr(SalesTable)).cursor();
           
            next applyState();
    
            switch (this.parmFormRun().name())
            {
                case formStr(SalesTable):              
               
                CustTable   custTable = CustTable::find(salesTable.CustAccount);
                if(custTable.Approval == NoYes::Yes)                                      
                    
                {
                   this.enableButton(formControlStr(SalesTable, buttonUpdatePickingList), false);
                   this.enableButton(formControlStr(SalesTable, buttonUpdatePackingSlip), false);
                }                   
                
                else
                {
                   this.enableButton(formControlStr(SalesTable, buttonUpdatePickingList), true);
                   this.enableButton(formControlStr(SalesTable, buttonUpdatePackingSlip), true);
                }
                    
            }
    
        }
    
    }

    Thank you 

    Sona Jee

  • WillWU Profile Picture
    22,359 on at
    RE: How to enable disable generate picking list button based on condition

    Hi Sona,

    Please try to code in the OnInitialized event handler of the form.

    [FormEventHandler(formStr(SalesTable), FormEventType::Initialized)]
    public static void SalesTable_OnInitialized(xFormRun sender, FormEventArgs e)
    {
    FormDataSource salesTable_ds = sender.dataSource(formDataSourceStr(SalesTable,SalesTable)) as FormDataSource;
    SalesTable salesTable= salesTable_ds.cursor();

    }

  • André Arnaud de Calavon Profile Picture
    296,568 Super User 2025 Season 2 on at
    RE: How to enable disable generate picking list button based on condition

    Hi Sona,

    This button is also updated by some other logic from standard Dynamics 365. Check where this coding is exactly and see if you can extend that method instead of this data source event.

  • Sona Jee Profile Picture
    on at
    RE: How to enable disable generate picking list button based on condition

    Hi Andre,

    Thanks for the response

    My condition is that when we create sales order for that particular customer account we have added on checkbox in master like this:

    approval.png

    If this checkbox is set to yes then this generate picking list button will be disable.

    And my current code showing no results.

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]
        public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
            SalesTable      salesTable                  = sender.cursor();
            FormDataSource  salesTable_ds               = sender.formRun().dataSource("SalesTable");
            FormRun         element                     = sender.formRun();
            FormControl     buttonUpdatePickingList     = element.design(0).controlName("buttonUpdatePickingList");
    
            CustTable   custTable = CustTable::find(salesTable.CustAccount);
            if(custTable.Approval == NoYes::Yes)
            {
                buttonUpdatePickingList.enabled(false);            
            }
            else
            {
                buttonUpdatePickingList.enabled(true);
            }

    When i debugged its going in the condition but not disabling the button.

    So please help me how to do.

    Thank you

    Sona Jee

  • André Arnaud de Calavon Profile Picture
    296,568 Super User 2025 Season 2 on at
    RE: How to enable disable generate picking list button based on condition

    Hi Sona,

    What is your exact condition and where exactly do you need help? Did you test your coding? What is the current result of this?

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 > Finance | Project Operations, Human Resources, AX, GP, SL

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans