Wednesday, December 9, 2015

X++ code to change the table field properties

static void Esh_Test(Args _args)
{
 str myProp,myProp1;

 #AOT


 NumberSequenceList   numberSequenceList; //Table Name

 TreeNode            numSeqFldsRoot = treeNode::findNode(@"\Data Dictionary\Tables\NumberSequenceList\Fields\Status"); //Field Path

 TreeNode           numSeqFldsRoot1 = treeNode::findNode(@"\Data Dictionary\Tables\NumberSequenceList\Fields\TransId"); //Field Path

 TreeNode           table = treeNode::findNode(@"\Data Dictionary\Tables\NumberSequenceList"); //Table Path

;


  numSeqFldsRoot.AOTsetProperties("PROPERTIES\n AllowEdit #" + 'No' + "\n ENDPROPERTIES\n"); // We use AOTsetProperties method to  set or manipulate the field properties.


  numSeqFldsRoot1.AOTsetProperties("PROPERTIES\n AllowEdit #" + 'No' + "\n ENDPROPERTIES\n");



  myProp = numSeqFldsRoot1.AOTgetProperties();
  myProp1 = numSeqFldsRoot.AOTgetProperties();

  numSeqFldsRoot.AOTsave();
  numSeqFldsRoot1.AOTsave();
  table.AOTsave(); // Saving the table.

  info(myProp);
  info(myProp1);
   
 
}

Wednesday, December 2, 2015

Multi-Select Lookup Control and grid filteration Using X++

1.Create a Form

2.Go to Design node and then select a StringEdit Control

3.Name the control as Multilookup - Set auto declaration to Yes to access the control using X++

4.Add a button in order to get values on button click

5.Now open the Class Declaration node of the form and write the following code into it

   SysLookupMultiSelectCtrl msCtrl;

6.Override the init method of the form and write the following code in it


Query query = new Query();

QueryBuildDataSource qbds;

super();

//creating query to show customer account and customer name

//the query must contain only those fields that should be visible on the lookup

qbds = query.addDataSource(tableNum(CustTable));

qbds.fields().dynamic(YesNo::No);

qbds.fields().addField(fieldNum(CustTable,AccountNum));

qbds = qbds.addDataSource(tableNum(DirPartyTable));

qbds.fields().dynamic(YesNo::No);

qbds.fields().addField(fieldNum(DirPartyTable,Name));

qbds.relations(true);

//assigning control and query to the class

msCtrl = SysLookupMultiSelectCtrl::constructWithQuery(element, MultiLookup, query);


Note :- if you are using the AOT query you can using the below code

msCtrl = SysLookupMultiSelectCtrl::construct(element, MultiLookup, queryStr(queryname));


7.Now  override the clicked method of the Button

void clicked()
{
    CustTrans           custtrans1;
    CustTable           custtable;
    DirPartyTable       dir;
    List                strlist   = new List(Types::String);
    ListIterator        iterator;
    container           packedList, c,v;
    int i;


    ;

    strlist=strSplit(CustTrans_AccountNum.valueStr(),";");
    iterator = new ListIterator(strlist);
    while(iterator.more()) // Additionally, to move to the next item in a list, you must explicitly call the more and next methods if you are using a list iterator.

    {
       //filtering the grid based on the selected customers and Trans Date.
        while select custtrans1
        where custtrans1.AccountNum ==  iterator.value()               
         && custtrans1.TransDate >= Proj_CustTrans_kkr_FromDate.dateValue()
         && custtrans1.TransDate <= Proj_CustTrans_kkr_ToDate.dateValue()

        {
            Proj_CustTrans_kkr.CustAccount = custtrans1.AccountNum;
            Proj_CustTrans_kkr.Name = DirPartyTable::findRec(CustTable::find(custtrans1.AccountNum).Party).Name;
            Proj_CustTrans_kkr.AmountCur = custtrans1.AmountCur;
            Proj_CustTrans_kkr.TransDate = custtrans1.TransDate;
            Proj_CustTrans_kkr.insert();
        }
        iterator.next(); // Additionally, to move to the next item in a list, you must explicitly call the more and next methods if you are using a list iterator.
    }

    Proj_CustTrans_kkr_ds.research();
    Proj_CustTrans_kkr_ds.refresh();
    CustTrans_ds.research();
    CustTrans_ds.refresh();

    super();


}


Tuesday, December 1, 2015

Importing Unit of Measures of AX 2009 to 2012 using EXCEL.

UNIT_Excel (Importing Units of 2009)
==============================
static void Unit_Excel(Args _args)
{
    Dialog dialog;
    DialogField dialogfield;
    Filename filename;

    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;

    COMVariantType type;
    int row;
    UnitOfMeasure unitofmeasure,UnitFM;

    ;

    dialog = new dialog("FileOpen");
    dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
    dialog.run();

    if(dialog.run())
    {
     filename =(dialogfield.value());
    }

    row=1;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();

    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

     workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
    {
    row++;
    unitofmeasure.DecimalPrecision=any2int(cells.item(row,1).value().double());
    unitofmeasure.Symbol=cells.item(row,2).value().bStr();
    unitofmeasure.SystemOfUnits=any2int(cells.item(row,3).value().double());
    unitofmeasure.UnitOfMeasureClass=any2int(cells.item(row,4).value().double());
    UnitFM=unitofmeasure::findBySymbol(unitofmeasure.Symbol,true);
        if(UnitFM)
    {
        ttsBegin;
        UnitFM.selectForUpdate(true);
        UnitFM.update();
        ttsCommit;
    }
    else
        unitofmeasure.insert();

    info(strfmt('%1 ', unitofmeasure.RecId ));
    type = cells.item(row+1, 1).value().variantType();

    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();

}

-===================================================================
UOM_Excel ( Importing Unit of Measures of 2009)
====================================================================

static void UOM_Excel(Args _args)
{
    Dialog dialog;
    DialogField dialogfield;
    Filename filename;

    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;

    COMVariantType type;
    int row,cnt=0;
    UnitOfMeasureConversion unitOfMeasureConversion, unitofmeasure;
    ;

    dialog = new dialog("FileOpen");
    dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
    dialog.run();

    if(dialog.run())
    {
     filename =(dialogfield.value());
    }

    row=1;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();

    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1);
    cells       = worksheet.cells();
    do
    {
        row++;
        unitOfMeasureConversion.Product             = EcoResProduct::findByProductNumber(cells.item(row, 1).value().bStr()).Recid;
        unitOfMeasureConversion.ToUnitOfMeasure     = UnitOfMeasure::findBySymbol(cells.item(row, 4).value().bStr()).RecId;

        unitOfMeasureConversion.Factor              = cells.item(row, 3).value().double();

        unitOfMeasureConversion.Numerator           = 1;
        unitOfMeasureConversion.Denominator         = 1;
        unitOfMeasureConversion.FromUnitOfMeasure   = UnitOfMeasure::findBySymbol(cells.item(row, 2).value().bStr()).RecId;
        unitOfMeasureConversion.Rounding            = UnitofMeasureconversionrounding::Nearest;//cells.item(row, 5).value().bStr();
        unitofmeasure = UnitOfMeasureConversion::findByConversion(unitOfMeasureConversion.FromUnitOfMeasure, unitOfMeasureConversion.ToUnitOfMeasure,unitOfMeasureConversion.Product);
        if( unitOfMeasureConversion.ToUnitOfMeasure!=0 &&  unitOfMeasureConversion.FromUnitOfMeasure!=0)
         {
          if(unitofmeasure)
          {
            ttsBegin;
            unitofmeasure.selectForUpdate(true);
            unitofmeasure.update();
            ttsCommit;
          }
          else
             {
            unitOfMeasureConversion.insert();
                 cnt++;
             }
          info(strfmt(' Conversions imported for the products=%1 ', EcoResProduct::findByProductNumber(cells.item(row, 1).value().bStr()).DisplayProductNumber ));

         }
        else
        {
            info(strfmt('Conversions are not imported for products=%1 ',  EcoResProduct::findByProductNumber(cells.item(row, 1).value().bStr()).DisplayProductNumber ));

        }
         type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    info(strFmt('No Of Conversions imported are=%1',cnt));
    application.quit();


}

--------------------------------------------------------------------------------------------------------------------------

Below is the method to check the Text format


static void UOM_Excel(Args _args)
{
    Dialog                         dialog;
    DialogField                 dialogfield;
    Filename                    filename;

    SysExcelApplication  application;
    SysExcelWorkbooks  workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells              cells;
 
    EcoResProduct          ecoResProduct;
    InventTable                inventtable;
    ItemId                        itemid;
 
    COMVariantType      type;
    int                              row,cnt=0;
    UnitOfMeasureConversion unitOfMeasureConversion, unitofmeasure;
    ;

    dialog = new dialog("FileOpen");
    dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
    dialog.run();

    if(dialog.run())
    {
     filename =(dialogfield.value());
    }

    row=1;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();

    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1);
    cells       = worksheet.cells();
    do
    {
        row++;
     
     
        switch(cells.item(row, 1).value().variantType())
        {
        case COMVariantType::VT_BSTR:
            itemid = strFmt("%1", cells.item(row, 1).value().bStr());
            break;
        case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
            itemid = strFmt("%1", any2int(cells.item(row, 1).value().double()));
            break;
        case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
            itemid = strFmt("%1", cells.item(row, 1).value().int());
            break;
        case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
            itemid = strFmt("%1", cells.item(row, 1).value().uLong());
            break;
         case COMVariantType::VT_EMPTY:
            itemid = '';
            break;
        default:
            throw error(strfmt('Unhandled variant type (%1).', cells.item(row, 1).value().variantType()));
        }

     
     
     
        if(itemid)
        {
         
        inventtable = InventTable::find(itemid);  
         
        unitOfMeasureConversion.Product             = inventtable.Product;
        unitOfMeasureConversion.ToUnitOfMeasure     = UnitOfMeasure::findBySymbol(cells.item(row, 4).value().bStr()).RecId;

        unitOfMeasureConversion.Factor              = cells.item(row, 3).value().double();

        unitOfMeasureConversion.Numerator           = 1;
        unitOfMeasureConversion.Denominator         = 1;
        unitOfMeasureConversion.FromUnitOfMeasure   = UnitOfMeasure::findBySymbol(cells.item(row, 2).value().bStr()).RecId;
        unitOfMeasureConversion.Rounding            = UnitofMeasureconversionrounding::Nearest;        unitofmeasure = UnitOfMeasureConversion::findByConversion(unitOfMeasureConversion.FromUnitOfMeasure, unitOfMeasureConversion.ToUnitOfMeasure,unitOfMeasureConversion.Product);
     
        if( unitOfMeasureConversion.ToUnitOfMeasure!=0 &&  unitOfMeasureConversion.FromUnitOfMeasure!=0)
         {
          if(unitofmeasure)
          {
            ttsBegin;
            unitofmeasure.selectForUpdate(true);
            unitofmeasure.update();
            ttsCommit;
          }
          else
             {
            unitOfMeasureConversion.insert();
                 cnt++;
             }
          info(strfmt(' Conversions imported for the products=%1 ', inventtable.ItemId));

         }
        else
        {
            info(strfmt('Conversions are not imported for products=%1 ',  inventtable.ItemId));

        }
        }
        else
        {
            info(strfmt('Item not found: %1',cells.item(row, 1).value().bStr()));
        }
         type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    info(strFmt('No Of Conversions imported are=%1',cnt));
    application.quit();


}


Saturday, November 21, 2015

How to open the Child form using X++

Error :- Dynamics AX form requires an active buffer

Here is the code for above explanation: -

        Args                    argsForm;
        FormRun             formRun;
        FormRun             subformRun;
        ;
   

        //Open Picking List form
        argsForm = new Args(formstr(ProdJournalTable));
        argsForm.record(ProdJournalTable::find(prodJournalTable.JournalId));
        formRun = classFactory.formRunClass(argsForm);
        formRun.init();
        formRun.run();


        //Now open sub-form (Production Journal Lines)
        argsForm = new Args(formstr(ProdJournalTransBOM));
        //Here you can mention the parent form instance as an active buffer
        argsForm.caller(formRun);    
        argsForm.record(ProdJournalTable::find(prodJournalTable.JournalId));

        subformRun = classFactory.formRunClass(argsForm);
        subformRun.init();
        subformRun.run();
        formRun.close(); //Now close the parent form.
        subformRun.wait(); //This halts your programme execution.

Wednesday, November 4, 2015

How to change the Infolog limit in AX 2012 ?

Hi Folks !

Recently I got a requirement to import a list of Items in AX  and  also I have to make a list of Imported item. Well the problem was the list exceed 10000 Limit.

Default limit of Infolog messages is 10000. I have found a solution for this limit.

You can change the value of  MaxErrors macro in viewBuild() method of Info class


Hope this information will help you

Friday, October 16, 2015

An Unbalanced X++ TTSBEGIN/TTSCOMMIT pair has been detected

Issue :- I was trying to import the class in the application and when I click on any button to import or cancel the import I was getting this error as An unbalanced X++ TTSBEGIN/TTSCOMMIT. which means there are too many TTSBEGIN/TTSCOMMIT  statements.

And the TTS level is "2".

At this unable to import the class as the dialog box throws error on all the buttons.

To resolve this error you need to remove all the extra TTSBEGIN/TTSCOMMIT from the code.

This can be done with the simple Job which is return below.


To resolve this error this TTS level should be ZERO, Run this job to get rid of that error, this job will find the tts level where its greater than zero and make it zero by calling TTSABORT.
static void TheAxaptaResetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    {
        info(strfmt("Level %1 aborted",appl.ttsLevel()));
        ttsAbort;
    }
}


Understanding TTSBEGIN /TTSCOMMIT 


ttsBegin: marks the beginning of a transaction. This ensures data integrity, and guarantees that all updates performed until the transaction ends (by ttsCommit or ttsAbort) are consistent (all or none).

ttsCommit: marks the successful end of a transaction. This ends and commits a transaction. MorphX guarantees that a committed transaction will be performed according to intentions.


I got the above information from the below source :
https://community.dynamics.com/ax/b/axaptavsme/archive/2013/08/29/error-an-unbalanced-x-ttsbegin-ttscommit-pair-has-been-detected-in-ax

above blog is very helpful you will get the help for most of the solutions.


Tuesday, October 13, 2015

Table Relations in AX 2012

What is Table Relation ?

A table relation associates two tables that contain related information. Usually the primary key field of one table appears as a foreign key field of the related table. The table with the primary key is called the parent table. The table with the foreign key is called the child table.

For example, a parent table named Department can have a departmentId field as its primary key. A child table named Employee can have a departmentId field as a foreign key.

Detail Explanation :- https://msdn.microsoft.com/en-us/library/aa675395.aspx


The foundation of Microsoft Dynamics AX is the relational database. Relationships can be created between tables that contain related data. In Microsoft Dynamics AX, the relationship between tables is called a relation.

Relations in Microsoft Dynamics AX:
  • Keep the database consistent (enforce referential integrity).
  • Are used by the Auto Join system in forms.
  • Enable the look up of values in other tables (through lookup list/selection list boxes and the View details Form command).
  • Are used to validate data.
  • Automatically propagate changes from one table to another.
  • Auto-define table relationships in queries.

Table relations are most commonly used in form fields to enable the look up of information in another table. If a table relation exists, the lookup button can be used to display a lookup list of values for a particular field.

A table relation is created by specifying one or more fields in a table that contain the same value in a related table. The matching fields typically have the same name in each table.

For example, a SalesOrder table containing orders might have a field called SalespersonID, which identifies the salesperson that took the order. The Salesperson table, containing the names of sales people, would also have a field called SalespersonID.

To create a table relation, specify that the SalesOrder.SalespersonID field is related to the Salesperson.SalespersonID field.

Source :- https://msdn.microsoft.com/en-us/library/bb190076.aspx

Adding a Relation to a Table :-
  1. In the AOT, move to Data Dictionary > Tables, and then expand the table that the relation will be added to.
  2. Right-click the Relations node, and then select New Relation.
  3. Right-click the newly added relation, and then select Properties.
  4. Set the name of the new relationship by modifying the Name property.
  5. In the Table property, select the related table.
  6. Use the Validate property to determine whether the relation should be used to validate data when information is entered into forms.
  7. Right-click the new relation, select New, and then click one of the following:
  • Normal to specify relation fields without conditions.
  • Field fixed to specify relation fields to restrict the records in the primary table.
  • Related field fixed to specify relation fields that restrict the records in the related table.
  • ForeignKey to specify a correspondence between a foreign key field in the present table to the primary key field in another parent table.

Conditional Table Relations :-

Define conditional table relations to filter the records in either the primary or the related table. Following are the conditional table relations that can be specified when you define the fields in a table relation:

  • Field fixed
  • Related field fixed
You create a conditional relation by right-clicking the  AOT > Data Dictionary > Tables > YourTable > Relations > YourRelation node. Then click either Field fixed for Related field fixed.

Understanding the Conditions :-

Field Fixed :- Table.Field == <EnumValue>

Restricts the records selected in the primary table. Only records that meet the condition are selected.
The condition is ANDed with your relation.

Related field fixed :- (<EnumValue> == Table.Field)

Restricts the records selected in the related table. Only records that meet the condition are selected.
The condition is ANDed with your relation.



ForeignKey Relation :

ForeignKey to specify a correspondence between a foreign key field in the present table to the primary key field in another parent table.

There are 2 ways of creating foreign key relation:


  • PrimaryKeyBased- Primary key is the unique index specified in the Parent table PrimaryIndex property. It can consists of 1 or more fields


  • SingleFieldAlternateKeyBased- Alternate key is an unique index specified in the Parent table, with its AlternateKey property set to Yes. However, to be eligible for use for creating foreign key relation, The alternate key can only consist of a single field.

Normal Relation :

To specify relation fields without conditions.

Sunday, October 4, 2015

Compile , CIL (Incremental CIL and Full CIL) in AX 2012

well developers new to AX always get hard time to understand compile , Full CIL and CIL , I have jotted down few points from different sources to understand these concepts

Compile :- When the Microsoft Dynamics AX application is compiled, its X++ source code is translated into a machine-executable format that can be interpreted by the Microsoft Dynamics AX server and clients.

What is CIL? 

CIL stands for Common Intermediate Language and it works together with the CLI or Common Language Infrastructure, which is basically a set of rules on programming languages that will compile with the CIL.



Picture is taken from the source:- http://axwonders.blogspot.in/2013/04/ax-2012-cil-how-does-it-work.html, which explains the same process in detail

The Common Language Runtime (CLR) that ships with .NET understands the Common Intermediate Language and knows how to execute that code.  The CLR does not need to understand all of the different languages (like C#, VB or F#) it needs to only understand the one language they all get mapped down to, CIL.

In AX you program in X++ and the equivalent of AX's CLR is the kernel.  When you build or compile your X++ code it traditionally gets mapped down to a p-code language that the kernel understands and knows how to execute.

In AX 2012 for certain classes that is what has changed. Now when you compile the X++ code gets mapped down to the Common Intermediate Language.  Then the CLR understands what the code says and executes it -here kernel is not needed.


Write, save, and compile your X++ class :- The X++ source code for your class is automatically compiled into p-code when you save the source in the AOT.

Compile the p-code into CIL :- X++ is compiled into p-code. The p-code can be compiled into CIL by the following menu:

AOT > Add-ins > Incremental CIL generation from X++

Note:- The CIL generation process writes files to an AOS installation subdirectory. The directory path could resemble the following: C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin\XppIL\


we have two types of CIL compilations, the incremental CIL and the full CIL compilation.

Full CIL :- generate CIL is about to convert the p-code into CIL, referred to as the byte code which, at run time, is used by the CLR to convert into native code for execution on the computer. It is easier to understand that a full CIL generation involves converting all p-code into CIL, finally it converts to the binary Language.

Incremental CIL :- incremental CIL generation involves only the “changed” p-code artifacts that need  to be converted into target CIL. Incremental CIL would compile only the objects that were modified since the last incremental compilation.

In short the major difference between the two of them is that the incremental CIL would compile only the objects that were modified since the last incremental compilation.

Note :- if the installation uses multiple instances of Application Object Server (AOS), all AOS instances must be stopped and then restarted. This causes the AOS instances to load the updated assembly.




Thursday, September 24, 2015

How to List Models in a Model Store in AX 2012

List models (Windows PowerShell) :-

1.To list the models in a layer, at the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.

      Get-AXModel -Layer <LayerName>

2.To list the models in the model store, at the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.

   Get-AXModel


List models (AXUtil) :-

  1. On the Start menu, click Command prompt.
  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
  3. To list the models in a layer, at the command prompt, type the following command, and then press ENTER.
        axutil list /layer
        :<layername> 

    4.To list the models in the model store, at the command prompt, type the following command, and then                    press ENTER.
       
        axutil list

src :-https://technet.microsoft.com/EN-US/library/hh433542.aspx


-------------------------------------------------------------------------------------------

AxUtil and Windows PowerShell Commands for 

Deploying Models in AX 2012


Two command line tools are available for deploying and managing models and the model store:
  • Windows PowerShell, a command-line scripting tool
  • AXUtil, a command-line utility

Access Windows PowerShell

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, enter the Get-Help command, and then press ENTER. 
                  Get-Help AXModel (The command in this example returns a list of all model-related cmdlets.)

         Get-Help Export-AXModel -Full (The code in this example retrieves help for the Export-AXModel cmdlet.)

Export an .axmodel file (Windows PowerShell)

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
           Export-AXModel –Model <name> -File <Filename.axmodel>

This example exports the specified model to a file that has the specified file name.
You can use the –Server–Config, or –Database parameters to specify the environment to export from.

Import an .axmodel file (Windows PowerShell)

  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.
           Install-AXModel -File <Filename.axmodel> -Details

           This command installs the specified file in the same layer that it was exported from.
You can use the –Server–Config, or –Database parameters to specify the environment to import to.


AxUtil

After you install Microsoft Dynamics AX, the applicable AXUtil commands are available from the directory for Microsoft Dynamics AX Management Utilities.
To view the Help for AXUtil, enter the command AXUtil /?.

Access AXUtil

  1. On the Start menu, click Command prompt.
  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
  3. At the command prompt, type the following command, and then press ENTER.
             axutil /? (This command displays the Help for AXUtil.)

Export an .axmodel file (AXUtil)

  1. On the Start menu, click Command prompt.
  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
  3. At the command prompt, type the following command, and then press ENTER.
          axutil export /model:<modelname> /file:<filename> /verbose

This example exports the specified model to a file that has the specified file name.

Import an .axmodel file (AXUtil)

  1. On the Start menu, click Command prompt.
  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.
  3. At the command prompt, type the following command, and then press ENTER.
           axutil import /file:<filename> /verbose

This command installs the specified file in the same layer that it was exported from.
If the installation fails because of a conflict, we recommend that you rerun the command, and use the /conflict:push option to push the element that has the conflict to the related update layer. You can then resolve the conflict. For more information, see How to: Resolve Conflicts After Importing a Model.

src:- https://technet.microsoft.com/EN-US/library/hh352314.aspx
src:- https://technet.microsoft.com/EN-US/library/hh456294.aspx




Wednesday, September 23, 2015

Model, Model Stores and Base Line Data base in ax 2012:



Database :- 

AX Databases include

  • The Microsoft Dynamics AX database, 
  • The Model Store, and
  • The Baseline database. 


The AOS connects to the Microsoft Dynamics AX database to process transactions.
The AOS connects to the Model store to display application elements such as forms and reports.

Baseline Database:- The baseline database contains a model store that is used to upgrade X++ code to Microsoft Dynamics AX 2012. The baseline database is used to analyze application updates before they are applied.


Models:
A model is a set of elements in a given layer. Each layer consists of one or more models. Each layer contains one system-generated model that is specific to that layer. Every element in a layer belongs to only one model. In other words, no element can belong to two models in the same layer, and every element must belong to a model.

A model is permanently associated with the layer that is created in. If you need to move one of your models from one layer to another, you must create a project from the model in the AOT, export the project as an xpo file, create a target model in the desired layer, delete the original model to avoid having to resolve layer conflicts, and import the xpo file to the target model. If you are moving elements between models in the same layer, you can use the Move to model command in the AOT.

Models are stored in Model Store.

Model Store :-
The model store is the database where all application elements for Microsoft Dynamics AX are stored. Customizations are also stored in the model store. The model store replaces the Application Object Data (AOD) files that were used in earlier versions of Microsoft Dynamics AX.

Models that have been installed in the model store are used at run time.

Note: Models can be exported to files that have the .axmodel extension. These files are called model files. Model files are deployment artifacts. Model files can be signed with strong name signing and Microsoft Authenticode signing.

*Important :-
In Microsoft Dynamics AX 2012 R2, the model store was moved into a database that is separate from the business database. The name of the model store consists of the name of the business database plus _model.

Layer information and model information are integral parts of the model store. The Application Object Server (AOS) has access to the model store. The AOS manages layer flattening or overshadowing at runtime. That is, when you make an object modification in one layer, the modification overshadows the object on a lower layer at runtime. You could, for example, decide to change a caption on a standard form. The change is saved on your layer only, and the revised—or flattened—form replaces the standard form at runtime. The AOS also provides all the Microsoft Dynamics AX subsystems with model data, such as form rendering, report rendering, and X++ code.
Microsoft Dynamics AX contains sixteen layers. Each layer consists of one or more logical parts called models. A model is generated for each layer. For example, VAR Model is the model that the system generates for the VAR layer. The system-generated models let you install and work with the base Microsoft Dynamics AX system. When you customize the Microsoft Dynamics AX program, you can take advantage of the capabilities of models.

The model store is used in the following ways in Microsoft Dynamics AX:

Installation – During installation, the Setup program uses axutillib.dll to import the .axmodel files from the installation path into the model store.

Upgrade – During an upgrade, the application files, or AOD files, from the earlier version are imported into the model store, which is the new model. The application files are also imported into the baseline model store, or the model store for the earlier version of the metadata. The baseline model store is similar to the old folder in earlier versions of Microsoft Dynamics AX.

Development environment – In the development environment, developers can continue to use .xpo files to export and import code. Use .axmodel files to migrate application elements from one environment to another, such as from a development environment to a test environment. Export models from the source system to .axmodel files, and then import .axmodel files into the target system.

Run time – At run time, an Application Object Server (AOS) instance retrieves the application elements, such as forms, reports, and classes, from the model store to respond to client requests.

The following diagram provides an overview of the model store architecture.




https://technet.microsoft.com/en-us/library/gg732276.aspx
https://technet.microsoft.com/en-us/library/dd362019.aspx

Thursday, September 10, 2015

List of important tables for Role Based Security in AX 2009 and AX 2012




AX 2009 Tables :-

UserGroupList :-
The UserGroupList table contains the list of users associated with each user groups in Ax.

UserGroupInfo:- The UserGroupInfo table contains the list of available user groups in Ax.

UserInfo           :-The UserInfo table contains the list of users in Ax and their Active Directory information and default company information.

AccessRightsList Table :- Group rights

UtilIdElements :- The UtilIdElements table contains the application model shown in the AOT.

UtilElements :- The UtilElements table contains the application model shown in the AOT.

AX 2012 Tables :-

SecurityRole
           :-The SecurityRole table reflects the list of roles defined by the security AOT role node.

SecurityUserRole    :-The SecurityUserRole table contains the user to role mappings.

SecurityTask           :-The SecurityTask table contains the list of duties and privileges that have been defined by the AOT security duty and security privilege nodes.

SecuritySubTask    :- The SecuritySubTask table contains the duty to privilege mappings that have been specified on the security duty AOT nodes.

SecurityRoleTaskGrant  :-The SecurityRoleTaskGrant table contains the list of role to duty mappings and role to privilege mappings as defined by the AOT security role node.

SecurityTaskEntryPoint :- The SecurityTaskEntryPoint table contains the list of privilege to entry point mappings that have been specified on the AOT security privilege node.

OMUserRoleOrganization :-The OMUserRoleOrganization table maintains the mapping between user roles and organizations.

OMInternalOrganization  :-The OMInternalOrganization table is the base table for each of the organizations.

How to fetch the UserGroup and Permissions Using X++ in AX 2009



static void Esh_UserGroup(Args _args)
{

 AccessRightsList accessRightsList;
 UserGroupList  userGroupList;
 UserGroupInfo userGroupInfo;
 UtilIdElements utilIdElements;
 ;

 while select UserGroupList
 join UserGroupInfo
 where UserGroupInfo.Id == UserGroupList.groupId
 join AccessRightsList
 where AccessRightsList.groupId == userGroupInfo.id

 {
  select * from utilIdElements;
  {
  info(strFmt("%1,%2,%3,%4", userGroupList.userId,userGroupList.groupId,accessRightsList.accessType, accessRightsList.elementName));
  }
 }


}

====================================================================


static void Esh_MenuItems(Args _args)
{
 AccessRightsList accessRightsList;
 UserGroupList  userGroupList;
 UserGroupInfo userGroupInfo;
 UtilIdElements utilIdElements;
 ;

while select UserGroupList
 join UserGroupInfo
 where UserGroupInfo.Id == UserGroupList.groupId
 join AccessRightsList
 where AccessRightsList.groupId == userGroupInfo.id
{
select * from utilIdElements;
 {
 Info(strFmt("%1,%2",userGroupInfo.id,accessRightsList.elementName));
  }
}
}

Thursday, September 3, 2015

How to fetch the list of table related to each module with the help of security key using X++

static void Esh_FindTablesFromSecKey(Args _args)
{
    // The name of the Security key to be specified here
    str                     secKeyName      = "smmCRM";
    Dictionary              dictionary      = new Dictionary();
    SecurityKeyId           secKeyId        = dictionary.securityKeyName2Id(secKeyName);
    TableId                 tableId;
    DictSecurityKey         dictSecurityKey;
    DictTable               dictTable;
    container               keyIds;
    int                     i;
    ;

    if (secKeyId)
    {
        // Find all children of the specified Security key
        for (i = dictionary.securityKeyNext(0); i; i = dictionary.securityKeyNext(i))
        {
            dictSecurityKey      = new DictSecurityKey(i);          

            while (dictSecurityKey.parentSecurityKeyId())
                dictSecurityKey = new DictSecurityKey(dictSecurityKey.parentSecurityKeyId());

            if (dictSecurityKey.id() == secKeyId)
                keyIds += i;
        }

        // Find all tables that have an appropriate Security key
        i = 0;
        for (tableId = dictionary.tableNext(0);tableId;tableId = dictionary.tableNext(tableId))
        {
            dictTable = new DictTable(tableId);
            if (!dictTable.isMap() && !dictTable.isTmp() && !dictTable.isView())
            {
                if (confind(keyIds, dictTable.securityKeyId()))
                {
                    i++;
                    info(dictTable.name());
                }
            }
        }
    }

    info(strfmt("%1 tables have Security key '%2'", i, secKeyName));
}

Wednesday, September 2, 2015

How to fetch the list of tables of each module with the help of configuration key using X++

static void FindTablesFromConfigKey(Args _args)
{
    // The name of the configuration key to be specified here
    str                     configKeyName   = "Bank";
    Dictionary              dictionary      = new Dictionary();
    ConfigurationKeyId      configKeyId     = dictionary.configurationKeyName2Id(configKeyName);
    TableId                 tableId;
    DictConfigurationKey    dictConfigurationKey;
    DictTable               dictTable;
    container               keyIds;
    int                     i;
    ;

    if (configKeyId)
    {
        // Find all children of the specified configuration key
        for (i = dictionary.configurationKeyNext(0); i; i = dictionary.configurationKeyNext(i))
        {
            dictConfigurationKey = new DictConfigurationKey(i);

            while (dictConfigurationKey.parentConfigurationKeyId())
                dictConfigurationKey = new DictConfigurationKey(dictConfigurationKey.parentConfigurationKeyId());

            if (dictConfigurationKey.id() == configKeyId)
                keyIds += i;
        }

        // Find all tables that have an appropriate configuration key
        i = 0;
        for (tableId = dictionary.tableNext(0);tableId;tableId = dictionary.tableNext(tableId))
        {
            dictTable = new DictTable(tableId);
            if (!dictTable.isMap() && !dictTable.isTmp() && !dictTable.isView())
            {
                if (confind(keyIds, dictTable.configurationKeyId()))
                {
                    i++;
                    info(dictTable.name());
                }
            }
        }
    }

    info(strfmt("%1 tables have configuration key '%2'", i, configKeyName));
}

Friday, August 28, 2015

How to find out number of field & field names in the table using X++

static void DictTable(Args _args)
{
dictTable dt;
DictField df;
int numberOfFields;
int fieldId;
int i;
str table;
;

table = 'salestable';
dt = new dictTable(tablename2id(table));
numberOfFields = dt.fieldCnt();
info(strFmt("%1",dt.fieldCnt()));
for (i = 1; i <= (numberOfFields); i++)
{
fieldId = dt.fieldCnt2Id(i);
df = dt.fieldObject(fieldId); //instead of we can use below line.
info(df.label());    

}
 
}

Wednesday, August 26, 2015

Abstract Class and Abstract Method


Abstract Class:

Abstract classes are classes that contain one or more abstract methods.

An abstract method is a method that is declared, but contains no implementation.

When we declare a class as abstract, this class cannot initiate in X++ code. To use this class or its method we have to first extend this class than only we are able to use this class or its method.


This is often used in the standard package for super classes to control that the super class is not declared by mistake. 

The class SalesFormLetter which is used for creating documents such as sales confirmations and sales invoices uses this practice. 

The class has an construct() method which should be used, and to prevent the class being declared using new() 

SalesFormLetter is qualified as abstract.



To understand the abstract class consider following example

We have three classes
     1.      absClass  (it’s an abstract class)
     2.      normalClass (an another class which will use the absClass methods)
     3.      extendAbsClass (this class will extends the absClass)

    1.abstract class absClass
     {
     }

    void printName()
   {
    ;    info("AbsClass... Deepak");
   }


    2. class extendAbsClass extends absClass
       {
        }

    3.class normalClass
      {
      }

  void accessAbsClass()
{
    absClass        absClass;
    extendAbsClass  extendAbsClass;
    ;
 //   absClass = new absClass();    // this declaration will throw error “Object could not be created because class absClass is abstract” so first we extend absClass into extendsAbsClass and further use extendsAbsClass to access absClass methods.
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.printName();
}


Abstract Method:

When we declare a method as abstract, this method should be overload in child class or we can say , this method  should be declare/initiate in child class, than only we can use this class or its method.
Note:
a.      Abstract methods may only be declared in abstract classes.
b.      No code or declarations are allowed in abstract methods.

We have three classes
i.                    absMethodClass
ii.                  extendAbsClass
iii.                NormalClass

1.      abstract class absMethodClass
{
}

abstract void absPrintName()
{
                        // we cannot declare any code in abstract method
}

2.      class extendAbsClass extends absMethodClass
{
}

void absPrintName()
{
    ; // we have to initiate abstract method here as this class extends the abstract class.
    info("abstract method declaration in derived class");
}
3.      class childClass_1
{
}

void accessAbsClass()
{
    extendAbsClass  extendAbsClass;
    ;
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.absPrintName();

}


Conclusion : 

  • Abstract classes can't be instantiated
  • they're explicitly intended to be extended. 
  • They also usually contain abstract methods, i.e. methods without any implementation that must be implemented by any non-abstract child. 
  • It allows you to define high-level concepts and provide some common functionality and leave details for concrete implementations. 


For example, RunBaseBatch class is abstract - it can't be used by itself because it doesn't define any action to run, but you can extend it and inherit a huge amount of functionality common to all batches.

Wednesday, August 12, 2015

Interview Questions

Data dictionary
1.What is an EDT, Base Enum, how can we use array elements of an EDT,
2.Definition and use of Maps, how AddressMap (with methods) is used in standard AX
3.What is the difference between Index and Index hint?
Utility and use of find method.
4.How many types of data validation methods are written on table level?
5.How many types of relations are available in Axapta, Explain each of them.
6.When the recid is generated, what is its utility, what are the different types of Table groups defined on table properties.
7.Difference between Primary & Cluster index.
8.How many kind of lookups can be made and how.
9.How can we utilize field groups in forms
10.How many types of Delete Actions are there in Standard Ax and define the use of each
11.If any record is created in table I want to fetch the date & time stamp, how will you do that
12.What is the function of super()


Classes
1. What is an abstract class, what is the utility of an abstract method
2. Multiple inheritance possible or not, if not how can we overcome that.
3. What is an interface, Why do we implement it
4. Do we need to write main method, give reasons
5. What is difference between new & construct method
6. What is the utilty of the RunOn property
7. What is main class used in batch process OR which class will you inherit to make a batch job
8. How can we make a batch job occur at regular interval
9. What is the main utility of classes in standard Ax
10. Which class is called when we create a SO/PO.
11. What are classes used to write query.
12. What is a static method, why do we make static methods and where can we write it.
13. When do we make methods private or protected.Forms
14. What is the basic structure of a form
15. Utility of init(), run(), wait() methods
16. What are different types of Link Types available in a form datasource, justify each of them
17. Properties of a form datasource
18. validateWrite() method can be written in form datasource as well as table level, when should we write it in form DS and when in table. Similar in case of write() method
19. How can we call table level methods from form DS (similar methods)
20. What is the difference between form init() & DS init()
21. When a form opens what are the sequential methods called.
22. Where is the best place to write code to perform filter in a form
23. What are the different types of menu items available, explain each of them
24. A action type menu item is attached to a form but in the drop down the menu item is not appearing, what could be the problem

Report
1. What are the two most important methods
2. When do block the super() method of fetch
3. Can we make a report from wizard, if yes from where
4. What is a Programmable Section, how we use it in reports
5. What is the difference between Auto Design Spec & Generated Design
6. How can we sort the DS, what facility we can get in by placing fields in Ranges
7. What is the role of executeSection
8. What are Queries, how do we use them

 Menu Items
1. What is the use of Parameter, Enum TypeParameter/Enum Parameter properties of display
2. Why do we provide Configuration key & Security key
3. Normally what do we attach in Output
4. Normally what do we attach in Action

 General Questions
1. What is difference between select & select firstonly statements
2. What are the keywords used to access data from "multiple companies" and "one company to another company".
3. How can we override a lookup
4. How do the following methods work in a form DS.
ds.refresh(), ds.research(), ds.reread(), in what situation we should these methods
5. On closing a form name the methods which are invoked
6. What are security key/configuration keys, how do we use it in Ax
7. How can we provide user level/user group level security
8. What is a virtual company
9. What is Visual MorphXplorer, what do we do with that?(Reverse engineering tool has replaced Visual MorphXplorer)
10. What is the function of Application Hierarchy Tree
11. If you want to monitor the database activity, where can you get that
12. Where can we find the Label log and what is its utility
13. What are the tools you will use to upgrade any object
14. What is the difference between display() and edit() methods, how do we use each
15. What is the use of System Documentation/Application Developer Documentation/Application Documentation

 Few More Questions on DAX
1.What are the classes, Tables, Forms and Methods used to post the sales orders.
2. What are the classes, Tables, Forms and Methods used to post the purchase orders.
3. What are the classes, Tables, Forms and Methods used to post the Ledgers.
4. What are the classes, Tables, Forms and Methods used to post the Inventory.
5. What is the base class to send the on-boad E-mailing.
6. What are the storage Dimensions?
7. What are the Item Dimensions?
8. What is the difference between RunBase and RunBaseBatch?
9. How do you create a NumberSequence for existing Module and also fro new Module.
10.What is the difference between Insert and doinsert.
11.What is the Runbase Stack?


DIFFERENCE BETWEEN SQL AND X++ STATEMENT--
SELECT-
1.Table buffer on the FROM in x++ clause ,not the table as in SQL
2.ORDER BY clause precedes the WHERE clause
3.! for negation ,not NOT as in SQL
4.&& and || for logical operator ,not AND or OR as in SQL.
5.* and ? for like wildcards ,not % and _ as in SQL.

JOIN CLAUSE-

1.Join clause has no ON keyword in x++,use WHERE instead
2.Defauld JOIN direction is left .
3.there are no LEFT and RIGHT keyword for JOIN in x++
4.The FROM clause is optional when:
-No column is listed or
-Only one table is listed in the SELECT in x++

select * FROM CustTable;
select CustTable;

both are same.

OTHERS-
1.The WHILE SELECT statement provides an automatic cursor for return rows in x++
2.There is no HAVING keyword in x++
3.No null values are return in x++

Differrence between RunBase and RunBaseBatch class

RunBase: To create a job or an Action class - a program that carries out processes, such as accepting parameters from the user and then updating records in the database - you use the RunBase framework.
The framework is implemented by the RunBase application class and supplies many features, which include the following:
· Query
· Dialog, with persistence of the last values entered by the user
· Validate

The RunBase application framework runs or batches an operation.

An operation is a unit of work, such as the posting of a sales order or calculation of a master schedule.

The RunBase framework uses the Dialog framework to prompt a user for data input.

It uses the SysLastValue framework to persist usage data and the Operation Progress framework to show operation progress.

The RunBase class is a framework for classes that need a dialog for user interaction and that need the dialog values to be saved per user.

RunBaseBatch:  You can design your own batch job by extending the RunBaseBatch class. You can also write code to schedule the batch to run. The batch runs on the Application Object Server (AOS)

RunBaseBatch is an extension of RunBase - it adds a support for batch processing.

SysOperation framework is a newer framework replacing RunBase (and its extensions such as RunBaseBatch).

It provides better separation of concerns, generation of dialogs from data contracts and quite a few additional features.

class RunBaseBatch extends RunBase implements Batchable

Differences between reread(), refresh(),research()


When working with Forms, commonly after opened the form we need to do some operations with existing data. In few cases we need to interact with data base again and again in order to do. For that we will use these methods. But some times its create confuse what exactly use of these methods, when should we call these methods and why, here is brief info these methods...

refresh() : this method will refresh the data in the data source cache. But it will not interact with the data base to fetch the new/updated record values. What ever values have fetched in the previous query will store in data source cache, this method will just refresh the data source cache only.

reread(): this method will interact with the data base and runs the query against the data base in order to fetch the new/updated record values. But this will not show the updated values in the form until calling the refresh method. that means it will update the data source form cache only but not existing form control values.
So it is better to call the methods as shown here, like reread and after refresh methods in order to fetch the new / updated values from the data base.

formDataSource.reread()
formDataSource.refresh()

research():Calling research() will rerun the existing form query against the database, therefore updating the list with new/removed records as well as updating all existing rows.

executeQuery() is another useful one.  It should be used if you have modified the query in your code and need to refresh the form.  It's like research() except it takes query changes into account.

List page interaction class and methods

Interaction class of list pages extends SysListPageInteractionBase class. Some handful methods of this class are as follows:

 initializing: Called when the form is initializing – Similar to the form init method

 intializeQuery: Also called when the form is initializing – Similar to the datasource init method

 selectionChanged: Called when the active record changes – Similar to the datasource active method.

 setButtonEnabled: Should be overridden to dynamically enable/disable buttons based on the current selection. This is called from the selectionChanged method.

 setButtonVisibility: Should be overridden to show/hide buttons when the form first opens. This is used more to do a one-off layout adjustment based on system configuration/parameters, as well as the menu-item used to open the form. eg If you have a menu-item that opens a form based on status, you may want to hide the relevant ‘status’ field to reduce clutter.

Thursday, July 2, 2015

Exporting data to an XML file

class CreateXmlFile
{
}


public static void main(Args _args)
{
XmlDocument doc;
XmlElement nodeXml;
XmlElement nodeTable;
XmlElement nodeAccount;
XmlElement nodeName;
MainAccount mainAccount;
#define.filename(@'C:\Users\XYZ\Desktop\AX(FolderName)\accounts.xml')
doc = XmlDocument::newBlank();  /*----Create a new XML Document------*/
nodeXml = doc.createElement('xml'); /*----Create its root node named xml using the createElement() method ------*/
doc.appendChild(nodeXml); /*-----add the node to the document by calling the document's
appendChild() method. ------*/
while select RecId, MainAccountId, Name from mainAccount
{
nodeTable = doc.createElement(tableStr(MainAccount));
nodeTable.setAttribute(fieldStr(MainAccount, RecId),int642str(mainAccount.RecId));
nodeXml.appendChild(nodeTable);
nodeAccount = doc.createElement(
fieldStr(MainAccount, MainAccountId));
nodeAccount.appendChild(
doc.createTextNode(mainAccount.MainAccountId));
nodeTable.appendChild(nodeAccount);
nodeName = doc.createElement(
fieldStr(MainAccount, Name));
nodeName.appendChild(
doc.createTextNode(mainAccount.Name));
nodeTable.appendChild(nodeName);
}
doc.save(#filename);
info(strFmt("File %1 created.", #filename));
}

/* Explaination for the code */

Next, we go through the MainAccount table and do the following for each record:
1. Create a new XmlElement node, which is named exactly as the table name, and add
this node to the root node.
2. Create a node representing the account number field and its child node representing
its value. The account number node is created using createElement(), and its
value is created using createTextNode(). The createTextNode() method
basically adds a value as text with no XML tags.
3. Add the account number node to the table node.
4. Create a node representing the account name field and its child node representing
its value.
5. Add the account name node to the table node.
Finally, we save the created XML document as a file.

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// &l...