Monsieur Winner

MS D365FO || Monsieur D365FO

Technical

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;
 }

}

Komi Siabi

Komi Siabi is a Bilingual D365FO Solution architect who loves sharing his knowledge as he works on Both Francophone and Anglophone projects around the globe. He enjoys doing some tiktok videos in his leisure time.

Leave a Reply

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