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

button enabled or disabled in form without refresh

(0) ShareShare
ReportReport
Posted on by 30

Hi team,

I wrote below code to enable or disable the buton. 

class SalesInvoiceOrgActiveEventHandlers
{
    /// 
    /// to enable or disbale SalesInvoiceOriginal button based on setup in Cust parameter.
    /// 
    /// 
    /// 

    

    [FormDataSourceEventHandler(formDataSourceStr(CustInvoiceJournal, CustInvoiceJour), FormDataSourceEventType::Activated)]
    public static void CustInvoiceJour_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        #Define.SalesInvoiceOriginal('SalesInvoiceOriginal')
        CustInvoiceDuplicateTable_W     custInvoiceDuplicateTable_W;
        CustInvoiceJour                 custInvoiceJour = sender.cursor();
        FormRun                         element         = sender.formRun();
        FormControl                     SalesInvoiceOriginal    = element.design(0).controlName(#SalesInvoiceOriginal);
        FormDataSource                  custInvoiceJour_ds;
        CustParameters                  custParameters = CustParameters::find();

        // This condition is to added to control the SalesInvoiceOriginal button to get disable once the report got executed for 1st time
        // for the current record.
        if (custParameters.RestrictOrgPreview == NoYes::Yes && custInvoiceJour.OrgPreviewPrint == NoYes::Yes)
        {
            SalesInvoiceOriginal.enabled(false);
        }
        else
        {
            SalesInvoiceOriginal.enabled(true);
        }     
    }
    
}

The button is working fine for enabled or disbaled. Once I refreshed the form then only it work properly.

I am looking for enabled or disabled the button without refreshing the form. Kindly let me know what to do?

Please give me more shed on this.

thanks!

I have the same question (0)
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: button enabled or disabled in form without refresh

    You can try 2 things.

    First is to write code in active method for the form ds. Because coc is much faster and best in performance when compared to handler and handler only when that event happens

    Second is to call ds.research(); and ds.refresh();

  • Suggested answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: button enabled or disabled in form without refresh

    Hi,

    Try calling FormDataSourceName_ds.research();

    Thanks,

    Girish S.

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: button enabled or disabled in form without refresh

    You cannot say COC is best in performance when compared to event handlers.

    COC will be easy to use for coding when compared to event handlers but there is no difference between performance.

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: button enabled or disabled in form without refresh

    This is because you need to enable or disable the button based on condition if original print view of report is printed.

    After clicking on print original the form datasource should be refreshed.

    Before if condition please use sender.reread()

    Sender.refresh()

    Although never used sender directly but you can try it doesn't work then map formdatasource variable custInvoiceJour_ds and use it as custInvoiceJour_ds.reread() and then custInvoiceJour_ds.refresh

  • @rp@n Profile Picture
    30 on at
    RE: button enabled or disabled in form without refresh

    Hi Girish,

    FormDataSourceName is not declared in our code. Is any format  to declare that.

    pls let me know

  • Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: button enabled or disabled in form without refresh

    FormDatasource custInvoiceJour_ds = sender;

    Use above line of code to declare it.

  • @rp@n Profile Picture
    30 on at
    RE: button enabled or disabled in form without refresh

    thanks Mohit

    You mean something like this?

    pastedimage1682690788895v1.png

    is it correct?

    But why before If ?

    pls give me more shed on this.

    thanks!

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: button enabled or disabled in form without refresh

    You need to call that after the if and else condition.

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    30 on at
    RE: button enabled or disabled in form without refresh

    Hi all,

    pastedimage1682691205973v1.png

    is it correct now?

    pls confirm

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: button enabled or disabled in form without refresh

    It should be like that.

    if (custParameters.RestrictOrgPreview == NoYes::Yes && custInvoiceJour.OrgPreviewPrint == NoYes::Yes)
    {
        SalesInvoiceOriginal.enabled(false);
    }
    else
    {
        SalesInvoiceOriginal.enabled(true);
    }  
    CustInvoiceJour_ds.reread();
    CustInvoiceJour_ds.refresh();

    Refresh should be after the if condition.

    Thanks,

    Girish S.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,188

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 868 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans