Wednesday 17 May 2017

Want filter on display method on form in AX 2012


Here I want filter on ItemGroupName field of InventOnHandItem form
You need to write display method on form datasource and pass buffer as parameter.

display ItemGroupId itemGroupId(InventSum _inventSum)
{
   InventItemGroupItem inventItemGroup;
   select ItemGroupId from inventItemGroup 
            where inventItemGroup.ItemId  == _inventSum.ItemId
                && inventItemGroup.ItemDataAreaId == _inventSum.dataAreaId;
   return inventItemGroup.ItemGroupId;
}
display Name inventItemGroupName(InventSum _inventSum)
{
          return InventItemGroup::find(this.itemGroupId(_inventSum)).Name;
}
void context()
{
   int selectedMenu;
   real test;
   formrun fr;
   Args ag;
   Name strtext;
   querybuilddataSource qb1, qb2;
   queryrun qr;
   query q;
   PopupMenu menu = new PopupMenu(element.hWnd());
   int a = menu.insertItem('Find');
   int b = menu.insertItem('Filter');
   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.run();
           fr.wait();
           strtext = fr.design().controlName('FindEdit').valueStr();
           if(strtext)
           {
               q   = InventSum_ds.query();
               if ( ! q.dataSourceTable(tableNum(InventItemGroupItem)) )
               {
                   qb1 = q.dataSourceTable(tablenum(InventSum));
                   qb1 = qb1.addDataSource(TableNum(InventItemGroupItem));
                   qb1.relations( false );
                   qb1.addLink(FieldNum(InventSum,ItemId),FieldNum(InventItemGroupItem,ItemId));
                   qb1.addLink(FieldNum(InventSum,DataAreaId),FieldNum(InventItemGroupItem,ItemDataAreaId) );                            
                   qb1.joinMode(JoinMode::ExistsJoin);
                   qb2= qb1.addDataSource( tableNum( InventItemGroup) );
                   qb2.relations( false);
                   qb2.addLink( fieldNum(InventItemGroupItem, ItemGroupId), fieldNum(InventItemGroup, ItemGroupId));
                   qb2.joinMode(JoinMode::ExistsJoin);
                   qb2.addRange(FieldNum(InventItemGroup,name)).value(queryValue(strtext));
                   InventSum_ds.query(Q);
               }
               else
                   q.dataSourceTable(tableNum(InventItemGroup)).addRange(FieldNum(InventItemGroup,name)).value(queryValue(strtext));
               InventSum_ds.executeQuery();
           }
           break;
       case b:
               q   = InventSum_ds.query();
               if ( ! q.dataSourceTable(tableNum(InventItemGroupItem)) )
               {            
                   qb1 = q.dataSourceTable(tablenum(InventSum));
                   qb1 = qb1.addDataSource(TableNum(InventItemGroupItem));
                   qb1.relations( false );
                   qb1.addLink(FieldNum(InventSum,ItemId),FieldNum(InventItemGroupItem,ItemId));
                   qb1.addLink(FieldNum(InventSum,DataAreaId),FieldNum(InventItemGroupItem,ItemDataAreaId) );            
                   qb1.joinMode(JoinMode::ExistsJoin);
                   qb2= qb1.addDataSource( tableNum( InventItemGroup) );
                   qb2.relations( false);
                   qb2.addLink( fieldNum(InventItemGroupItem, ItemGroupId), fieldNum(InventItemGroup, ItemGroupId));
                   qb2.joinMode(JoinMode::ExistsJoin);
                   qb2.addRange(FieldNum(InventItemGroup,name)).value(queryValue(this.valueStr()));
                   InventSum_ds.query(Q);
               }
               else
                   q.dataSourceTable(tableNum(InventItemGroup)).addRange(FieldNum(InventItemGroup,name)).value(queryValue(this.valueStr()));                    
               InventSum_ds.executeQuery();
               break;
       case c :
           InventSum_DS.query().dataSourceTable(Tablenum(InventItemGroup)).clearRanges();
           InventSum_DS.executeQuery();            
           break;
       Default:
           break;
   }
}

Tuesday 16 May 2017

Get CountryRegionId of company in ax 2012

ComapnyInfo        companyInfo;

companyInfo =  CompanyInfo::find();

companyInfo.postalAddress().CountryRegionId;

Find Duns number of customer in AX 2012 using X++.

DirOrganizationBase     dirOrganizationBase;
CustTable                        custTable;

custTable = CustTable::find("0001");

select firstonly DunsNumberRecId
                 from dirOrganizationBase
                    where dirOrganizationBase.RecId == custTable.Party;
     
 DirDunsNumber::find(dirOrganizationBase.DunsNumberRecId).DunsNumber;

Change the color of single column in AX 2012


Override the displayOption() method of the form's datasource 
to change appearance of any row in the grid. You can set either the 
foreground or the background color of the row.


public void displayOption(Common _record, FormRowDisplayOption _options)
{
   _options.backColor(WinApi::RGB2int(0,255,0)); 
} 

For highlighting one or more cells, override the 

To highlight one or more individual cells, use 
the ._options.affectedElementsByControl() method. 

public void displayOption(Common _record, FormRowDisplayOption _options)
{
  _options.backColor(WinApi::RGB2int(0,255,0));
  _options.affectedElementsByControl(Control1.id());
  _options.affectedElementsByControl(Control2.id());
} 

You can change multiple cells this way but you cant 
assign different colors to different cells. You have to use only one 
color for any of the cells in the row.

Find SID - AX 2012

  1. Open Command Prompt.
  2. Once Command Prompt is open, type the following command exactly as shown here, including spaces or lack thereof:
    wmic useraccount get name,sid
    and then press Enter. 
  3. You should see a table, similar to the following, displayed in the Command Prompt window:
    Name            SID
    Admin           S-1-5-21-1180699209-877415012-3182924384-581
    Guest           S-1-5-21-1180699209-877415012-3182924384-604
    John            S-1-5-21-1180699209-877415012-3182924384-134
  4. This is a list of each user account in Windows, listed by user name, followed by the account's corresponding SID.
    

Get Item purchase price in AX 2012 through code



container price ;

price = PriceDisc::findItemPriceAgreement(ModuleInventPurchSales::Purch, ItemId, InventDim,                 Unit, today(), Qty, VendAccountNum, CurrencyCode, "0");

purchPrice            = conPeek(price, 0);

Get Filepath and Filetype from Filename in ax 2012


str filePath;
str fileNameString;
str fileType;
     
         
[filePath, fileNameString, fileType]  =  fileNameSplit(fileName);

Append character to string in AX 2012

strLFix


Syntax :-

client server public static str strLFix(
    str _str, 
    int _length, 
   [char _char])

Exaple :- 

strLFix("PRA",5,'0')

Output :-
PRA00

Add leading characters to string in AX 2012

strRFix


Syntax :-

client server public static str strRFix(
    str _str, 
    int _length, 
   [char _char])

Exaple :- 

strRFix("PRA",5,'0')

Output :-
00PRA

Index and Index hint in ax 2012

Using "Index": when you add the statement "index MyIndex", the Axapta kernel will add an "ORDER BY" with all the fields of the index.

Example: select * from InventTable index GroupItemIdx will generate the following SQL statement to the database:

SELECT A.ITEMGROUPID, A.ITEMID, A.ITEMNAME,.... FROM INVENTTABLE A ORDER BY A.ITEMGROUPID, A.ITEMID

The Index ItemGroupIdx of the InventTable exactly contains the two fields ItemGroupID and ItemId (in that order).
Using "Index", you still give the control of which index to use to the database optimizer. So, if the optimizer finds a better index to use, it will use it.

Using "Index hint": when you add the statement "index hint MyIndex", the Axapta kernel will add a statement to instruct the database to use that index and no other one.

Example: select * from InventTable index hint GroupItemIdx will generate the following SQL statement to the database:

SELECT /*+ INDEX(A I_175GROUPITEMIDX) */ A.ITEMGROUPID, A.ITEMID, A.ITEMNAME,.... FROM INVENTTABLE A

Using "Index hint", you take away the control of which index to use from the database optimizer. So, if there may be a better index, the database will not use it.