› Dynamics 365, Enterprise › Override Form DataSource method using Extensions in D3fO

Override Form DataSource method using Extensions in D3fO

 Sohagani Shah   Leave a comment

In this blog article, we will see how we can override Form Data source method using Extensions in Dynamics 365 Operations. Now as recommended by Microsoft we must avoid Overlayering and instead use Extension. For extension, we have to use pre or post event handlers methods. In this blog we will create event handler of OnActivated() method of SalesLine DataSource of form SalesTable.

Create a new Class:

class CFSActivateButton
{   

}

Copy and paste OnActivated() event handler of SalesTable DataSource in Class:

 

/// <summary>
/// To activate or deactivate Create Service Order button based on CFSProjId field of SalesLine
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]
public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{     

        FormDataSource      fds = sender.formRun().dataSource("SalesLine");
        SalesLine           salesline = fds.cursor();
        FormRun             fr = sender.formRun();
        FormControl         fc = fr.design(0).controlName("CreateServiceOrder");       

        if(salesLine.ProjID)
        {
            fc.enabled(true);
        }
        else
        {
            fc.enabled(false);
        }
    }

 


Liked it? Share it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.