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