Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Wednesday, July 30, 2014

How to enable disable controls of List Page through Interaction Class

To enable or disable an action pane button

  1. In the AOT, expand Forms and find the form for the list page where the action pane button appears. Use theInteractionClass property of the form to get the name of the interaction class for the list page.
  2. Expand Designs, expand Design, and then expand the Action Pane. Get the name of each action pane button that you want to enable or disable based on the list selection.
  3. Expand Classes, right-click the interaction class for the list page, click Override Method, and then clickselectionChanged. The Editor window opens and displays the selectionChanged method.
  4. Check that Control which you want to Enable or Disable has property AutoDeclaration is set to Yes.
Syntax:-
public void selectionChanged()
{
TableName TableBuffer = this.listPage().activeRecord(queryDataSourceStr(QueryName, DataSourceName));
Super();
if(Condition)   //like - if(TableBuffer.fieldName == Something)
this.listPage().actionPaneControlEnabled(formControlStr(FormName, ControlName),true);

Example:-
public void selectionChanged()
{
    Requisition requisition = this.listPage().activeRecord(queryDataSourceStr(RequisitionQuery, Requisition_1));
    super();
    if(requisition.WorkflowApprovalStatus == WorkflowApprovalStatus::Approved)
        this.listPage().actionPaneControlEnabled(formControlStr(RequisitionListPage,Edit),true);
    else
        this.listPage().actionPaneControlEnabled(formControlStr(RequisitionListPage,Edit),false);
  }


Thursday, June 19, 2014

What is Model and ModelStore in ax 2012

Basic Info:
Models were introduced in Microsoft Dynamics AX to help partners and customers more easily install and maintain multiple solutions side by side in the same layer. This topic introduces the concept of models, and describes how models relate to layers and label files. This topic also describes the model store, which is the part of the Microsoft Dynamics AX database in which models are stored. 


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.
ModelStore:
Models are stored in the model store. The model store is the part of the Microsoft Dynamics AX database in which 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.

How to manage Label files with Model:
In Microsoft Dynamics AX 2012, label files, or ALD files, are part of models. A label file must be added to a model before the model can be installed. After a model has been installed, ALD files are pulled from the model store to the local of Application Object Server (AOS) instance when the AOS is started. When the AOS is shut down, the ALD files are pushed back to the model store.
ALD files from earlier versions of Microsoft Dynamics AX are not part of a model file. However, you can import these files into the model store from the Label Files section of the Application Object Tree (AOT). Use the Create from file shortcut command.
Note: The ALD file from an earlier version of Microsoft Dynamics AX must not be located in the application folder of AOS. Otherwise, you cannot import the file.

Working with label files across solutions

It is recommend that you use one label file per solution to simplify installation.
If you find that you require multiple label files, it is recommend that you create a single shared, cross-solution label file and package it as a model file. Then, when you install solutions, you must install two models: the solution itself and the label model.
If you want to ship additional languages, you can add the languages to the solution model, increment the model's version number, and then reimport the model.

Monday, June 9, 2014

How to Install MICROSOFT DYNAMICS AX 2012 R3, Window Azure


OVERVIEW:-
·       Latest version of AX released on 1 may 2014.
·       It is a Demo version also known as V 1.0
·       Next major release ‘Rainier’ will release in 2015.

·       Microsoft has also made many enhancements to Warehouse Management and Retail Dynamics AX 2012 R3.

System Requirement:-
·       Windows Server 2012 R2
·       SQL Server 2014
·       Windows 8.1
·       Windows Azure(Iaas)
·       Internet Explorer 11


New Changes in AX 2012 R3:-

·       Automated deployment of AX 2012R3 in Windows Azure.
·       Building Microsoft AX services integration with the Microsoft Windows Azure Service Bus
·       Data synchronization to multiple instances of Microsoft Dynamics AX
·       Optimizing the performance of Microsoft Dynamics AX deployment
·       Create Microsoft Dynamics AX builds using the new X++ server-side parallel compiler
·       List of New Modules in Microsoft Dynamics AX 2012 R3 or New Modules in Microsoft Dynamics AX 2012 R3
      o  Warehouse Management
      o  Transportation Management
      o  Call Center
      o  Trade Allowance Management
                      o Retails Essentials

This is a list (not exhaustive) of some new or enhanced features:
·         Demand forecasting
·         Modern Point of Sales
·         Call center sales
·         Customer and vendor Rebate management
·         Product kits (retail)
·         Serial Number Tracking Enhancements
·         Product change management
·         Master Data Management
·         Hosting in Azure supported (IaaS)
·         Lifecycle Services
·         Support for Microsoft SQL Server 2014

      Globalization/ Localization of Ax 2012 R3:-
·       Austria
·       Brazil
·       France
·       Germany
·       Japan
·       Mexico
·       Russia
·       India(coming soon)

How to Install Dynamics AX 2012 R3:-

Prerequisites:-
·       Windows server 2012 R2 should be install
·       SQL server 2014 should be install
·       Uninstall all component of AX 2012 R2.

Step 1:-
Check all prerequisites.

Step 2:-
Select Components. Database, AOS (Application object server) and Client is must.

Step 3:-
Insert AOS name and port number.


Step 4:-
Next and finish.


What is Window Azure?
Azure is an open and flexible cloud platform that enables you to quickly build, deploy, and manage applications across a global network of datacenters that are managed by Microsoft. Azure enables cloud computing. Cloud computing is the delivery of computing capabilities as a service. Cloud computing makes it easy to access IT resources such as computers, networking, and storage.
You can deploy Microsoft Dynamics AX 2012 R3 on Azure. When you do, you may realize the following benefits:
·       Reduce costs
·       Save time
·       Gain flexibility

Azure offers three types of services:-
·       Software-as-a-Service (SaaS):- You use a web browser to use applications that are hosted in the cloud.

·       Platform-as-a-Service (PaaS):- You don’t manage or control the network servers or operating system.  It allows you to focus on the business logic of applications.

·       Infrastructure-as-a-Service (IaaS):- You have control over your virtual machines and the network configuration, but you don’t have to worry about hardware.


Difference between List, Set, Container and Map

Containers:
Containers are dynamic and have no limits. They can contain elements of
almost all data types: Boolean, integer, real, date, string, container,
arrays, tables, and extended data types. However, objects may not be stored
in containers.
Containers in AX are used very often. It’s easy to work with them. But…
data in containers are stored sequentially, and thus retrieved sequentially.
This means that containers provide slower data access if you are working with
_large numbers_ of records. In case of large numbers of records use temporary
tables.

List:
Lists are structures that may contain any number of elements that are
accessed sequentially. Lists may contain values of any X++ type. All the
values in the list must be of __the same__(this is the main difference
between lists and containers) type, given in the creation of the list. The
implementation of lists is such that traversal of the list elements is __very
fast.
Take a look for example at class Dialog addControl() method.
There controls are stored in ctrls List.

Map:
A map is a data type that associates one (key) value with another value [An
analog - a small table in memory with two fields: Keys, Values]. Both the key
and value values may be of any valid X++ type, including objects. The types
of the key and the value are given in the declaration of the map. The
implementation of maps is such that access to the values is _very fast_.
Don’t confuse map X++ types with Map objects in AOT, wich are used for
mapping tables with similar structures of fields
Set:
The functionality of Sets is similar with list.  A Set is just an unordered list of items, while a list of items held by a Map
are indexed via via a key.
Take look at
\Classes\sysLabel\LabelModuleId().
In any case use Search in AOT\Classes or Forms and look how are used
different X++ types in AX.

Thursday, May 22, 2014

Get Employee email with X++

public Email GetEmployeeEmailFromEmplId(EmplId emplId)
{
    Email       email;
    UserId      userId;
    ;
   
    if(!emplId)
        return '';

    userId = SysCompanyUserInfo::emplId2UserId(emplId);
    email = SysUserInfo::find(userId, false).Email;
   
    return email;
}

Wednesday, May 14, 2014

Import new Worker through code in ax 2012

Firstly create an excel file that contains some fields like name, searchname, personnal no and worker type.
then create a record and run this job
static void importRecord(Args _args)
{
    SysExcelApplication xlsApplication;
    SysExcelWorkBooks xlsWorkBookCollection;
    SysExcelWorkBook xlsWorkBook;
    SysExcelWorksheets xlsWorkSheetCollection;
    SysExcelWorksheet xlsWorkSheet;
    SysExcelRange xlsRange;
    SysExcelCells Cells;
    SysExcelCell RCell;
    CommaIO inFile;
    int nRow,i;
    DialogField dialogPath;
    Dialog dialog;
    Filename filename;
    Name Name;
    LegalEntity LegalEntity;
    HcmPersonnelNumberId PersonnelNo;
    HcmEmploymentType WorkerType;
    HcmWorker hcmWorker;
    DirPerson dirPerson;
    DirPartyTable DirPartyTable;
    HcmEmployment HcmEmployment;
    DirPersonName DirPersonName;
    HcmPersonPrivateDetails HcmPersonPrivateDetails;
    importworker importworker;
    NameAlias SearchName;
    LogisticsElectronicAddressLocator Telephone;
    LogisticsElectronicAddress LogisticsElectronicAddress;
    DirAddressBookPartyAllView DirAddressBookPartyAllView;
    HcmPositionDuration HcmPositionDuration;
    ;
    dialog = new Dialog("Import");
    dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
    dialog.run();
    if (dialog.run())
    {
    filename = (dialogPath.value());
    }
    inFile = new CommaIO (filename, 'R');
    if (!inFile || infile.status() != IO_Status::Ok )
    {
    throw error (strfmt("@SYS19312",filename));
    }
    try
    {
    xlsApplication = SysExcelApplication::construct();
    xlsWorkBookCollection = xlsApplication.workbooks();
    xlsWorkBookCollection.open(filename);
    xlsWorkSheetCollection = xlsApplication.worksheets();
    xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
    Cells = xlsWorkSheet.Cells();
    nRow = 2;
    RCell = Cells.Item(nRow, 1);
    while (RCell.value().bstr() != "")
    {
    Name = RCell.value().bStr();
    RCell = Cells.item(nRow,2);
    SearchName = RCell.value().bStr();
    RCell = Cells.item(nRow,3);
    PersonnelNo = RCell.value().bStr();
    RCell = Cells.item(nRow,4);
    WorkerType = str2enum(WorkerType,RCell.value().bStr());
    RCell = Cells.item(nRow,5);
    Telephone = RCell.value().bStr();
    DirPerson.Name=Name;
    hcmWorker.PersonnelNumber = PersonnelNo;
   // DirPartyTable.name = Name;
    HcmEmployment.EmploymentType = WorkerType;
    dirpersonname.FirstName =  Name;
    dirperson.NameAlias = SearchName;
    LogisticsElectronicAddress.Locator =  Telephone;
    //hcmWorker.Person=dirPerson.RecId;
    //exportImportRecords.income = income;
    //importworker.insert();
    //dirPerson.RecId=DirPartyTable.RecId;
    DirPerson.insert();
   // DirPartyTable.RecId=dirPerson.RecId;
    //DirPartyTable.insert();
    DirPersonName.Person=dirPerson.RecId;
    dirpersonname.insert();
    LogisticsElectronicAddress.insert();
    hcmWorker.Person=DirAddressBookPartyAllView.Party;
    hcmWorker.Person=dirPerson.RecId;
   // HcmEmployment.insert();
    hcmWorker.insert();
     HcmEmployment.LegalEntity = 5637148640;
     HcmEmployment.ValidFrom=2007-05-05T23:22:21;
    HcmEmployment.ValidTo = 2015-05-05T23:22:21;
    HcmEmployment.Worker=hcmWorker.RecId;
    HcmEmployment.insert();
    //hcmWorker.update();
    nRow++;
    RCell = Cells.Item(nRow, 1);
    }
    xlsApplication.quit ();
    xlsApplication.finalize ();
    info("Import completed");
    }
    catch( Exception::Error)
    {
    xlsApplication.quit ();
    xlsApplication.finalize ();
    ttsabort;
    info("Unable to process the excel import ");
    }
    }

Thursday, May 1, 2014

How to generate CIL(Common Intermediate Language) in Ax 2012

CIL
(Common Intermediate Language)

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. 
CIL (Common Intermediate Language), formerly known as MSIL (Microsoft Intermediate Language) or sometimes simply IL is a low-level language used by .NET Framework.
The runtime (CLR) doesn’t work directly with high-level languages like C#, it works with CIL and compilers of high-level languages simply generate CIL. The runtime handles CIL in the same way regardless it was generated from C#, Visual Basic, IronPython or from X++.
We have two types of CIL compilations, the incremental CIL and the full CIL compilation. 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.
Compile: -The compile is to convert x++ source code into p-code.

Synchronization:- Checking each and every table defining the value of your EDT
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.
Some X++ batch jobs can now complete in much less time. All X++ code that runs on the AX32.exe client still runs as interpreted p-code. However, all batch jobs now run as Microsoft .NET Framework CIL, which is often much faster than p-code.





How does it work?



How to Generate CIL?
By AX 2012:-



                                      “OR”
By cmd:-

"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe" \\server\share\yourconfigfile.axc -startupcmd=CompileIL


Classes, tables, and enums are types in the X++ language. X++ types can be compiled to CIL. The queries and forms in the AOT are not X++ types, and they cannot be compiled to CIL. This means there are a few minor cases where calls from CIL to X++ p-code can cause an exception.
Suppose a method that is running as CIL calls a method on a query. The query method calls the ClassFactory system class of Microsoft Dynamics AX. This case causes an exception to be thrown. The problem is that the CIL session does not have access to all the system classes, yet the query method makes a call to a system class.

On the XppIL folder, there is a bunch of files. These files are NetModule type files and they only contain type metadata and compiled code. 

There is a folder named “source”, and within this folder we find a bunch of files with the .xpp extension, which have x++ source code and are used to debug CIL code when working with services and batches. 
The “existence” of the source folder is directly related to our server configuration when choosing to enable debugging on the server. 









Sometimes while Generating we Got an error like this:-

For resolving this error firstly compile the full application & then Generate full CIL again. If error still exists do this step
Step 1: Stop the AOS

Step 2: Delete all of the source in the C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin\XppIL directory


Step 3: Start the AOS
Step 4: Perform a full compile
Step 5: Perform a full CIL generation




After a FULL CIL compilation I got the following errors:


I just went to the object in question and compiled them separately.





The  error will be resolved.