Showing posts with label FormDataSourceEventType::Activated. Show all posts
Showing posts with label FormDataSourceEventType::Activated. Show all posts

Wednesday, 12 August 2020

FormDataSourceEventType::Activated in d365

FormDataSourceEventType::Activated in d365

WRITE THE BELOW CODE IN NEW CLASS OR ANY OTHER CLASS.

MAKE SURE THAT YOU USE THE METHOD SIGNATURE PROPERLY.
EXAMPLE
class CustTableFormEventHandler
{
    [FormDataSourceEventHandler(formDataSourceStr(CustTable, CustTable), FormDataSourceEventType::Activated)]
    public static void CustTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        CustTable           custTable     = sender.cursor(); //selected record
        FormDataSource      custTable_ds  = sender.formRun().dataSource("CustTable"); //DataSource 
        FormRun             element       = sender.formRun(); //form element
        FormControl         myNewButton   = element.design(0).controlName("MyNewButton"); 
//button on the form
        myNewButton.enabled(false); // enabled or disabled the button
    }
}


another example
[FormDataSourceEventHandler(formDataSourceStr(HRMCompFixedEmpl, HRMCompFixedEmpl), FormDataSourceEventType::Activated)]
public static void HRMCompFixedEmpl_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
HRMCompFixedEmpl compFixedEmpl = sender.cursor();
FormDataSource hrmCompFixedEmpl_ds = sender.formRun().dataSource(“HRMCompFixedEmpl”);
FormRun element = sender.formRun();
FormControl control1= element.design(0).controlName(“HRMCompFixedEmpl_field”);

if(compFixedEmpl.Status == NoYes::Yes)
{
control1.enabled(true);
}
else
{
control1.enabled(false);
}

}

Thanks,
Vikas Mehta

Tuesday, 8 January 2019

ACTIVE METHOD IN D365 FORM DATASOURCE

FORM ACTIVE METHOD IN D365 DATASOURCE EVENT HANDLERS FOR Activated METHOD 

How to get the event handler for the init method for Init method in D365 forms
You can just write the below code in any new class or else if you have an existing one then just simply copy the code in the class.

The class declaration should read:
[ExtensionOf(formStr(FormName))]final class FormName_Extension{}

So if the form name is SalesTable then the code will be 
[ExtensionOf(formStr(SalesTable ))]
final class SalesTable_Extension{}

In some cases even a class without the extension signature i.e. [ExtensionOf(formStr(SalesTable ))] might not be required but in that case  the this object will not provide the objects in the intellisense.

Note that the class declaration is Final and cannot be further extended.
[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         myNewButton   = element.design(0).controlName("anybutton");

        anybutton.enabled(false);
    }

}

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...