OnActivated form method EventHandler X++ D365FO
Here is a simple snippet of the active method on form by Event handler.
Why use the active method ?
We want to show record in a particular field on a grid when a record is selected.
In my case, we want to display the Department code on Positions:
Human resources -> Positions -> All positions.
The business scenario here is, the human resources officer is more familiar with the Department code. To achieve this, we can add a new field and assign the department code on selection of the record.
Let’s create a class: A form event handler for HcmPosition form.
internal final class HcmPosition_Form_GEMS_Handler
{
}
internal final class HcmPosition_Form_GEMS_Handler
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataSourceEventHandler(formDataSourceStr(HcmPosition, HcmPositionDetail), FormDataSourceEventType::Activated)]
public static void HcmPositionDetail_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun form = sender.formRun();
FormDataSource HcmPositionDetail_ds = form.dataSource(formDataSourceStr(HcmPosition, HcmPositionDetail)) as FormDataSource;
HcmPositionDetail hcmPositionDetail = HcmPositionDetail_ds.cursor();
OMOperatingUnit operatingUnit;
select operatingUnit where operatingUnit.RecId == hcmPositionDetail.Department;
hcmPositionDetail.OMOperatingUnitNumber = operatingUnit.OMOperatingUnitNumber;
}
}
Your comment is awaiting moderation.
Im thankful for the post.Really looking forward to read more. Want more.