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