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.

Tuesday, 8 November 2016

Get company address through code in AX.

static void getCompanyAddress(Args _args)
{
    CompanyInfo companyInfo;
    DirPartyPostalAddressView postalAddressView;
    ;

    companyInfo = companyInfo::find();

    select firstFast postalAddressView
        where postalAddressView.Location == companyInfo.PrimaryAddressLocation;

    info(companyInfo.Name+ "," +postalAddressView.Address);
}

Get company information in AX 2012 using X++.

static void getCompanyInfo(Args _args)
{
    CompanyInfo companyInfo;
    Description tel,fax,Email,URL;
    ;

    companyInfo = companyInfo::find();

    Email = LogisticsElectronicAddress::findRecId(companyInfo.PrimaryContactEmail).Locator;
    fax = LogisticsElectronicAddress::findRecId(companyInfo.PrimaryContactFax).Locator;
    tel = LogisticsElectronicAddress::findRecId(companyInfo.PrimaryContactPhone).Locator;
    url = LogisticsElectronicAddress::findRecId(companyInfo.PrimaryContactURL).Locator;
 
    info(strFmt("Email - %1, Fax - %2, Tel - %3, URL - %4",Email,fax,tel,URL));
}

Change date format in AX



static void dateFormat(Args _args)
{
    info(strFmt("Today date is " +date2str(today(),123,DateDay::Digits2,DateSeparator::Hyphen,
        DateMonth::Short,DateSeparator::Hyphen,DateYear::Digits4)));
}

Monday, 10 October 2016

str2date function in AX.

static void str2Date(Args _arg)
{
    date d;
    ;
   
    d = str2Date("10/10/2016", 123);
   
    info(strFmt('%1', d));
    info(strFmt('%1', mkDate(dayOfMth(d), mthOfYr(d), year(d))));
}

Friday, 7 October 2016

strLen Function in AX.

strLen Function

Calculates the length of the specified string.

Syntax: int strLen(str text)

Example:

print strLen("prash");
pause;

Result : 5

strKeep Function in AX.

strKeep Function

Builds a string from only the characters in the first input string that are specified to be kept by the second string.
Or
Shows only specifield value of string

Syntax: str strKeep(str _text1, str _text2)

Example:

info(strKeep("prashant","pra"));

Result : praa

strIns Function in AX.

strIns Function

Builds a string by inserting one string into another.
Syntax: str strIns(str _text1, str _text2, int _position)

Example:

info(strIns("prashant","pra",3));

Result : prpraashant

strDel Function in AX.

strDel Function

Creates a copy of a string with the specified substring removed.

Syntax:
str strDel(
    str _text,
    int _position,
    int _number)

Example:

using strDel function Note: removes 2 letters from 4th letter onwards

info(strDel("Prashant",4,2));

Result : Praant

info(strDel("Prashant",4,-3));

Result : Phant

strColSeq Function in AX.

strColSeq Function

Converts all uppercase characters to lowercase characters and also converts all special  design characters like (ÁÎ to ai) to lowercase characters

Syntax:
str strColSeq(str text)

Example:
info(strColSeq("AbçDËãBCdé"));

Result : abcdeabcde

strCmp Function in AX.

strCmp Function 

Compares two text strings.

Note: 0 if the two strings are identical, 1 if the first string sorts earlier, or -1 if the second string sorts earlier.

Syntax:
int strCmp(str text1, str text2)
The comparison performed by this method is case-sensitive.

Example:
print strCmp("prash","prash");
pause;

Result :  returns 0 if two strings are identical

print strCmp("prash","PRA");
pause;

Result :  returns 1 if first string is executed first;

print strCmp("ddd","kkk");
pause;

Result : returns 1 if the second string executed first;

print strCmp("hhh","ooo");
pause;

Result : returns -1 if the second string executed first;