Monday, April 3, 2017

Lookup method on form using eventing Dynamics AX 7

How to create a lookup method on a form without writing any code on form and using event.

AX 7 provides a very nice feature called Events. Using that concept lookup can be build on form level without touching any code on that form. See the procedure below.
I added a new string field on InventBatch form using extension. I have requirement to create lookup on this field. Lets start the steps of doing


  1. Go to that control on form,expand the events node and click on copy event handler method.











   
 2. Create a class InventBatchEventHandler and paste.

  1. class InventBatchEventHandler
  2. {
  3.     /// <summary>
  4.     ///
  5.     /// </summary>
  6.     /// <param name="sender"></param>
  7.     /// <param name="e"></param>
  8.     [FormControlEventHandler(formControlStr(InventBatch, VesselName), FormControlEventType::Lookup)]
  9.     public static void VesselName_OnLookup(FormControl sender, FormControlEventArgs e)
  10.     {
  11.         SysTableLookup sysTableLookup =              SysTableLookup::newParameters(tablenum(VesselTable), sender);
  12.  
  13.         Query query = new Query();
  14.         QueryBuildDataSource qbds;
  15.  
  16.         sysTableLookup.addLookupField(fieldnum(VesselTable, VesselId), true);
  17.         sysTableLookup.addLookupField(fieldnum(VesselTable, Name));
  18.  
  19.         qbds = query.addDataSource(tablenum(VesselTable));
  20.  
  21.         sysTableLookupCreate.parmQuery(query);
  22.  
  23.         sysTableLookup.performFormLookup();
  24.   FormControlCancelableSuperEventArgs ce = _e as FormControlCancelableSuperEventArgs;
  25.     //cancel super() to prevent error.
  26.     ce.CancelSuperCall();
  27.     }
  28. }
Build the project and you will have the new lookup on control.

Please enjoy learning and comment below if you have any query or suggestion.

Understanding new concepts- Part 3 Dynamics 365 (AX 7)

TABLE EXTENSION

In case of table extension we have a option to extend metadata as well as method.
Extensions give us way to create new field, new relation, new group without customizing base table.















Extension has been created and we can now add new fields.







For extending the method on table i will ref. the below links. It is very useful and nice post on table method extension.


Please enjoy learning and comment below if you have any query or suggestion.













Sunday, April 2, 2017

Understanding new concepts- Part 2 Dynamics 365 (AX 7)

EXTENSION
I have explained the use of extension and how to use it for BASE ENUM in my first part of blog.
EDT Extension

EDT extension is usefull only in case of changing the below properties.
Label, Help Text, and String Size as you can see in below img. of extensions EDT property window


























An extension can be created for any EDT. See the example below how to create EDT extension.
Select EDT in AOT that you want to create Extension.
Right click and clink on create extension.













It will create extension EDT.








Now Rename the created EDT as BaseEdtName.AnyName. Like below.













EDT extension is finished and new changed property will reflect in system.

Topics to be continued..

Please enjoy learning and comment below if you have any query or suggestion.