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

How to enable disable generate picking list button based on condition

(0) ShareShare
ReportReport
Posted on by 430

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

  • Verified answer
    Sona Jee Profile Picture
    430 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,342 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
    283,860 Test role Public 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
    430 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
    283,860 Test role Public 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

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

#1
Jahanvi Profile Picture

Jahanvi 34

#2
PJ JohnPaul Profile Picture

PJ JohnPaul 5

#3
SudhanshuMSID Profile Picture

SudhanshuMSID 1

Overall leaderboard

Product updates

Dynamics 365 release plans