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.

Thursday, March 30, 2017

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

Extension
MS has introduced new feature called extension to avoid the overlaying of standard objects that cost to you for upgrade.
Why do we need to go for extension and what is the benefit of using extension?
There are couple of advantages of using extensions and avoid overlaying
  1.   It will keep all customization away from the standard MS object that will ease the process of    future upgrade.
  2.    Extensions are easier to maintain.
  3.    Extensions let you to extend the metadata. For example, you can add new fields to a table,  add new data source to form, add new fields on form design and many more thing can be done using extension approach.
  4.   X++ code can be extended, so that you can add methods and state to artifacts that are defined in other models without recompiling those models.
First let me tell you the AOT objects that can be extend.
  1.       Base Enum
  2.       Extended data type
  3.       Table
  4.       View
  5.       Query
  6.       Data entities
  7.       Class
  8.       Form
  9.       Menu
Now let’s see one by one how to use Extension for

      1.    Base Enum extesnion
Set the base enum property IsExtensible value to True. See the example below





























Now Right click and click on create extension



Name the extension as BaseName.AnyName (not necessary to be Extension as in below)



Now new enum value will be avail to use.

But in case of Enum MS has given restriction to extend and most of the Enum has property value set to false, means it can't be extend.

See example below.
  

Topics to be continued..

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

Saturday, April 14, 2012

Adding financial dimension in AX2012

Requirementà Create a new financial dimension with values linked to new table.
Solutionàfollow the below steps:

1.Create a new table example  AVI_ServiceType.
2.Create fields in table as Code and description in this example.
3.Create a new form using this table for creating new record.
4. Create a view name must be DimAttribute[entityName] .example .DimAttributeServiceType.
5.Root datasource of view must name as BakingEntity that point your entity table
6.View must contain the following fields
 Keyà recId of backingEntity must be int64.
Valueà field Code of the table backing data source.
Name à field Description of the table backing data source .
Override the delete method of table with following code.
Public void delete()
{
            If(!DimensionValidation::canDeleteEntityValue(this))
            {
                        Throw error(strfmt(“@SYS134392”,this.code));
            {
            DimensionAttributeValue::UpdateForEntityValueDelete(this);
             Super();
}
Override the renamePrimaryKey method of table with following code.
Public void renamePrimaryKey()
{
            Super();
            DimensionStorage::syncRenamedValue(this);
}
In order to clear the caches and have the new backing entity appear immediately, execute the
following line of code within a job:

static void Job1(Args _args)
{
DimensionCache::clearAllScopes();
info(‘ok’);
}

Sunday, February 19, 2012

Delete transaction of a specific company in AX 2009

To delete all the transaction of a company.
1- Go to AOT
2-Open the class node
3-Search on  SysDatabaseTransDelete class
4- Right click on the this class 
5-Choose open 
6-Click yes on the message box appear to you 

7-Info will appear to you "operation completed"

Filter by field functionality on display method

Override the context method of form control of display method. Following is the example of filtering customer name.

public void context()
{
    // super();
   Int      selectedMenu;
   real     test;
   formRun  fr;
   Args     ag;
   Name     strText;
   str          custAcc;
   CustTable    custTable;
   Container    cust;
     FormStringControl   fsc;
   PopupMenu    menu    =   new PopupMenu(element.hWnd());
   int a = menu.insertItem('Filter by field');
   int b = menu.insertItem('Filter by selection');
   int c = menu.insertItem('Remove filter');
   selectedMenu = menu.draw();
   switch(selectedMenu)
   {
        case -1 :
        break;
        case a :
        ag =  new args('SysformSearch');
        fr = new formrun(ag);
        fr.init();
        fsc = fr.design().controlName('FindEdit');
        fsc.text(customerName.ValueStr());//customerName is display control name
        fr.run();
        fr.wait();
       strText = fsc.valueStr();
       while select custTable where custTable.Name like strText
        {
            cust += custTable.AccountNum;
        }
        custAcc = con2str(cust);//custTable.AccountNum;
         if(fr.closesOk())
          AVI_ServiceOrderTable_ds.filter(fieldNum(AVI_ServiceOrderTable,CustAccount),custAcc);
         break;
        case b:
            strText = customerName.valueStr();
            select custTable where custTable.Name == strText;
             AVI_ServiceOrderTable_ds.filter(fieldNum(AVI_ServiceOrderTable,CustAccount),custTable.AccountNum);
            break;
        case c:
        AVI_ServiceOrderTable_ds.removeFilter();
         break;
   }
}