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

Announcements

No record found.

News and Announcements icon
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 56

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!

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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,843 Moderator on at

    Hi,

    Try calling FormDataSourceName_ds.research();

    Thanks,

    Girish S.

  • GirishS Profile Picture
    27,843 Moderator on at

    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,573 Moderator on at

    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
    56 on at

    Hi Girish,

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

    pls let me know

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    FormDatasource custInvoiceJour_ds = sender;

    Use above line of code to declare it.

  • @rp@n Profile Picture
    56 on at

    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,843 Moderator on at

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

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    56 on at

    Hi all,

    pastedimage1682691205973v1.png

    is it correct now?

    pls confirm

  • GirishS Profile Picture
    27,843 Moderator on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 366

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 360 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans