Mar 29, 2012

RecId details in AX


As we know that Dynamics Ax uses recid(Record Id) to uniquelly identify a record in the database. 

Advantage of RecId
 

1.By default system uses Recid (surrogate Key) as primary index, so if query optimizer didn't find any index to use then it will use RecId.

Dyamics Ax uses
 SystemSequence class(AOT->SystemDocumentation->Classes) to generate recId for table.
Using SystemSequence class you can reserve RECID's for your table.

Ax Kernel uses SystemSequences Table to generate the Recid for table as shown below
Goto AOT-> SystemDocumentation->Tables->SystemSequences ,

Mar 28, 2012

How to use ternary operator?


static void intro_ternaryOperator(Args _args)
{
    Boolean         a = true;
    ;
    info(a?"Customer name":"Coustomer account");

}

How to get dataAreaId ?


static void DataDic_ChangeCompany(Args _args)
{
    DataArea dataArea;
    CustTable custTable;
    ;
    while select dataArea
    {
        if (!dataArea.isVirtual)
        {
        info(strfmt("Company: %1", dataArea.Id));
            changeCompany(dataArea.id)
            {
            custTable = null;
                while select custTable
                {
                info(strfmt("%1, %2", custTable.dataAreaId, custTable.accountNum));
                }
            }
        }
    }
}

How to display the field values separating by comma?

This simple job displays all the itemnames horizontally separated by comma  of  PO (000386)  lines


static void myTest(Args _args)
{

    PurchLine               PurchLine;
    Str                         itemName;
    boolean                 multipleTrans = false;
    ;
    while select PurchLine
        where PurchLine.purchId  == '000386'
    {
            if (multipleTrans == true)
            {
                itemName += " ,  ";
            }
             itemName += PurchLine.Name;
             multipleTrans = true;
    }
     info(itemName);
}

 O/P :    High End Speaker - ash/14 inches ,  Projection Television Model 01

How to get the current month and day of the year ?


The below job gives the current month of the year

static void mthOfYrExample(Args _arg)
{
    int i;
    ;
    i = mthOfYr(today());
    info( "The number of the month in today's date is " + int2Str(i));

}

The below job gives the current day of the year


static void dayOfYrExample(Args _arg)
{
    date d = today();
    int i;
    ;
    i = dayOfYr(d);
    info( "Today's day of the year is " + int2Str(i));
 
}

     Just try this job
----------------------

static void dateExample(Args _arg)
{
    date d = today();
    str s;
    ;
    info(strfmt("%1,%2,%3",dayOfmth(d),mthofyr(d),year(d)));

}




How to validate the alphabets?


The below simple job checks that the given string contains only alphabets or not ...

static void TextBuffer_regularExpression(Args _args)
{
    TextBuffer txt = new TextBuffer();
    str msg = "ABCDEFGS";
    ;

    txt.setText(msg);
    txt.regularExpressions(true);   // activate regular expr in search


     // Regular expression to validate only alphabets
    if (txt.find("^[A-Z]+$"))
    {
        info("String contains only Alphabets");
    }
    else
    {
        info("String contains others characters");
    }

}

Mar 20, 2012

How to build a form ref form


Lookup form reference for EDT

Step 1 : Create one form with the required fields MyTable

               Under Form level
---------------------------------------
void init()
{
    ;
    super();

    element.selectMode( control_LookupField);
}


public void run()
{
    FormStringControl callingControl = SysTableLookup::getCallerStringControl(element.args());
    boolean filterLookup;
    ;

    filterLookup = SysTableLookup::filterLookupPreRun(callingControl,   control_LookupField  , TableName_ds);

    super();

    SysTableLookup::filterLookupPostRun(filterLookup, callingControl.text(),   control_LookupField ,  TableName_ds );
}

          Under form datasource node
-----------------------------------------


void init()
{
    Query   query = new Query();
    ;
    super();

    query.addDataSource(tablenum( MyTable));

    this.query(query);
}


Step 2 : Provide the name of form to the EDT in formref property





Mar 8, 2012

File handling


File Operation using WinAPI in Dynamics Ax

Finding files with WinAPI
Axapta’s WinAPI class has  lot of static methods to handle files. The  below example shows how to use some of these methods to find files.

The two methods used to fetch all files matching the search criteria are findFirstFile() and findNextFile(). Don’t forget to clean up after yourself with findClose().

The code also uses three different find methods:

*   fileExists(_name) returns true, if _name is an existing file
*   folderExists(_name) returns true, if _name is an existing file or folder
*   pathExists(_name) returns true, if _name is an existing folder

The example uses the infolog for output. As with any infolog beware of performance and limitation to 10.000 lines.


static void Test_WINAPI(Args _args)
{

#File

FileName fullFileName(FileName _path, FileName _fileName)
{
FileName pathName;
FileName fileName;
FileName fileExtension;
;
[pathName,fileName,fileExtension] = fileNameSplit(_fileName);
return _path + '\\' + fileName + fileExtension;
}

void findFiles(FileName _path,
FileName _fileName,
boolean _inclSubDir = true,
FileName _prefix = fullFileName(_path,_fileName))

{

FileName fileName;
int hdl;
;
setprefix(_prefix);
if (WinAPI::folderExists(_path))
{
[hdl,fileName] = WinApi::findFirstFile(fullFileName(_path,_fileName));
while (fileName)
{
if (WinAPI::fileExists(fullFileName(_path,fileName)))
info(fileName);
fileName = WinApi::findNextFile(hdl);
}
WinApi::findClose(hdl);
if (_inclSubDir)
{
[hdl, fileName] = WinAPI::findFirstFile(_path+'\\'+#AllFiles);
while (fileName)
{
if (strlwr(fileName) != strlwr(_fileName) &&
strlwr(fileName) != strlwr('.') &&
strlwr(fileName) != strlwr('..') &&
WinAPI::pathExists(fullFileName(_path,fileName)))

findFiles(fullFileName(_path,fileName), _fileName, _inclSubDir,
fileName);


fileName = WinApi::findNextFile(hdl);

}
WinApi::findClose(hdl);

}
}
}
findFiles('c:\\Program Files','*.doc');

}

Mar 1, 2012

How to get the information of query runing on datasource?

write the below line in fetch after the super();

info(this.query().dataSourceTable(tablenum(ProjInvoiceTable)).toString());

How to get the recId of the reports' body ?

The below can display the recId of the record which is executing in report

write below line after the super() in send()

info(strfmt('%1',_cursor.RecId));