July 11, 2017

How to use Form event ‘OnInitialized’ in Dynaics365

Hi Folk,

In Dynamics365 there are many standard events on Forms, similarly like standard methods on a different node of form. Let’s see how we can use ‘OnInitialized’ event on Form Data source and use form object into a different call.


Scenario: On from ‘ProjAdjustmentSplit’ I want to enable/disable a field on a certain condition. As D365 urge to not to customize ant standard object than write EventHandlers to achieve your requirement. In an earlier version of AX, we simply write this logic either on Form Active method or from DS init method. Here we have to use EventHandlder for the same.  Here we will use ‘OnInitialized’ method and will write an event handler for the same.
image

Let’s take a look.

Approach: Follow the below step to get this done,

Step 1: Right-click on “OnInitialized’ method and select ‘Copy event handler method’

image


Step 2: Create a new class and paste this method.
/// <summary>
///
     /// </summary>
     /// <param name="sender"></param>
     /// <param name="e"></param>
     [FormDataSourceEventHandler(formDataSourceStr(ProjAdjustmentSplit, TmpProjAdjustmentSplit), FormDataSourceEventType::Initialized)]
     public static void TmpProjAdjustmentSplit_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
     {
}

Step 3: Use below code to access form object
TmpProjAdjustmentSplit      tmpProjAdjustmentSplit         = sender.cursor();
         FormDataSource              tmpProjAdjustmentSplit_ds      = sender.formRun().dataSource('TmpProjAdjustmentSplit');
         FormRun                     element                     = sender.formRun();
         FormControl                 projID;
  
         projID= element.design(0).controlName("TmpProjAdjustmentSplit_ProjId");

Step 4: After above declaration now wrtie your actual business logic.
if(ProjParameters::find().myParameter== NoYes::Yes)
         {
             projID.allowEdit(false);
         }
         else
         {
             projID.allowEdit(true);
         }
Step 5: Now go to
Project management and accounting > Periodic > Transactions > Adjust transactions and click on the Adjust button to test your code.

Note: Try to add use the same code on your form and add more field using form control. Make sure you mark this control AutoDeclare = Yes on Form design.  Get the complete code here.


Enjoy…
Harry

June 13, 2017

Export license file [AX2009/2012]

Every now and then, there is a need to export license keys from a system.  I needed to get into the VAR layer to modify the code in a Microsoft VPC, but as we all know, Contoso license keys don't come with the BUS/CUS/VAR access codes.  So I did what any developer would do:
  • Write a job to export the Contoso license key file
  • Import my company's partner license key file
    • DO NOT SYNC when it asks
  • Jump in the VAR layer using our layer access code to make my changes real quick
  • Import back the Contoso license key file I exported from my job and SYNC
Here is said job, enjoy!