Showing posts with label active event handler syntax in d365. Show all posts
Showing posts with label active event handler syntax in d365. 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

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...