Dynamics Search Engine

Tuesday, January 6, 2015

How to read and insert record from a CSV file using X++ code into Microsoft Dynamics AX 2012 table

How to read and insert record from a CSV file using X++ code into Microsoft Dynamics AX 2012 table.

This article helps you to understand how to read data from a CSV file and insert into Microsoft Dynamics AX 2012 table.

Applied on: Dynamics AX 2012 R3.
Prerequisite
: Basic Dynamics AX 2012 programming knowledge.
Target audience
: AX programmers.
Assumption: You are familiar with Dynamics AX 2012 and CSV file


Below job inserts records from a CSV file to CustGroup table.

static void CustGroupCSVInsert(Args _args)
{
    Dialog          dialog  = new Dialog();
    DialogField     dialogField;
    AsciiIo         importFile;
    str             filePath,fileNameOnly;
    filetype        type;
    container       record;
    str             delimiter = ",";
    int             totalRecords;
    CustGroup       custGrp;

    dialogField=dialog.addField(extendedTypeStr(FilenameOpen),"Select File","Select file to import");
    dialog.caption("File Picker");
    dialog.filenameLookupFilter(['csv','*.csv']);

    if(!dialog.run())
        return;

    [filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
    importFile = new AsciiIo(dialogField.value(), 'R');

    if((!importFile) || (importFile.status() != IO_Status::Ok))
    {
        warning("Error in opening import file");
        throw(Exception::Error);
    }

    importFile.inFieldDelimiter(Delimiter);

    try
    {
        ttsbegin;
        custGrp.clear();
        record = importFile.read(); // First row - Column name - Header

        while(importFile.status() ==  IO_Status::Ok)
        {
            record = importFile.read();
            if(!record)
                break;

            totalRecords = totalRecords + 1;
            custGrp.clear();

            custGrp.CustGroup = conPeek(record, 1);
            custGrp.Name = conPeek(record,2);

            custGrp.insert();
        }
        ttscommit;
    }

    catch(Exception::Error)
    {
        Throw(Exception::Error);
    }

    info(strFmt("Total Read Records = %1",totalRecords));
}


Sample .CSV file image.



 

Friday, August 15, 2014

How to execute parallel compilation command on server side using AxBuild.exe for Microsoft Dynamics AX 2012 CU7 onwards

How to execute parallel compilation command on server side using AxBuild.exe for Microsoft Dynamics AX 2012 CU7 onwards

Overview:
The AxBuild.exe utility program enables you to accomplish a full compile of all the X++ code on your system much faster than you can with the MorphX client (native way). AxBuild.exe is run at a command prompt on a computer that hosts the Application Object Server (AOS). This approach eliminates the burden of transferring metadata between the AOS machine and the client machine. It starts several parallel processes and divides pieces of the full compile among them. Each piece is called worker. One set of workers generates 6 worker windows. It depends on the system that how many set of workers system will generate to make compilation faster.

AxBuild.exe is available in Microsoft Dynamics AX 2012 R3 or AX 2012 R2 + cumulative update 7 or later.

How to do it:
Step1: Log on to your AOS server for which you want to start the compilation.

Step2: On AOS server go to Start on task bar and compose cmd in Run to open command prompt.

Step3: Go to the bin folder of your AOS application. By default it should be “C:\Program Files\Microsoft Dynamics AX\60\Server\\bin\”. In this folder you will get AxBuild.exe executable file. Make sure the file is existing here. Note that the folder path can be different based on your installation.

<!--[if gte vml 1]>



Step4: Now you need to compose and execute the command. The command is AxBuild.exe xppCompileAll /s=01 “C:\Program files (x86)\Microsoft Dynamics AX\60\Client\Bin”. First parameter is to compile the application in whole, scond parameter is to consider the service number from AOS server. You may have more than one service on your AOS server. Third parameter is referring client bin folder if anything to be considered from there. The command window looks like:

<!--[if gte vml 1]>





Step5: Execute the command by pressing Enter key of your key board.

<!--[if gte vml 1]>










Once compilation is over it shows the details like when completed, how much time it took, log file location, number of workers completed the compilation etc.
Dynamics AX R2 was taking 4.5 hours to complete application compilation with native way but new way of compilation using AxBuild.exe only takes few minutes, not even an hour. It may take more than one hour if there are 6 workers.

You may leave your comments below.

Thursday, May 8, 2014

Microsoft Dynamics AX 2012 Database Entity Relationship Diagrams

Hello,

After a long time I got a chance to write here.
I was surfing internet and came out with a very useful link http://www.microsoft.com/dynamics/ax/erd/ax2012r2/ which tells about Microsoft Dynamics AX 2012 Database Entity Relationship Diagrams.

This link can answers your questions like:
How to know Microsoft Dynamics AX 2012 table relations?
In Microsoft dynamics AX 2012 how to know tables per module?
In Microsoft dynamics AX 2012 how to know parent child relationship for tables?

You can explore the content by Module.
This link is very useful for AX developers as well as functional people who are interested to know about Microsoft dynamics AX 2012 table relationship.


You may leave your comments below.

 

Friday, April 11, 2014

How to fix synchronization error ‘Cannot create a record in Version control changes (SysVersionControlTmpChange)’ with TFS while importing?

How to fix synchronization error ‘Cannot create a record in Version control changes (SysVersionControlTmpChange)’ with TFS while importing?

Applied on: Dynamics AX 2012 R2
Prerequisite: Basic Dynamics AX 2012 programming knowledge & basic knowledge of how to use Team Foundation Server (TFS).
Target audience: AX programmers
Assumption: You are familiar with Dynamics AX 2012, TFS and Visual Studio .Net

 
Symptom:

1)     When you try to synchronize a model with Team Foundation Server (TFS), it throws error like “Cannot create a record in Version control changes (SysVersionControlTmpChange). Change Number: [a numeric number]. The record already exists.”

 
2)     You try to synchronize an object with TFS and system throws errors “Cannot create a record in Version control changes (SysVersionControlTmpChange). Change Number: [a numeric number]. The record already exists.”

 
A sample error.

 
I was facing the above error and came up with a solution as below.

The above screenshot shows a RecID “5637527359”. I searched for this RecID in SysVersionControlSynchronizeLog table record and got the record, noticed that ItemPath field of this searched record shows a value where I can see AOT path for a view called DirPartyPostalAddressView.

Then I searched SysVersionControlSynchronizeLog table for view DirPartyPostalAddressView using ItemPath field as shown below.






It shows two entries (record) for DirPartyPostalAddressView in the searched result. Here system has two entries for DirPartyPostalAddressView so during TFS synchronization it tries to create two entries to table SysVersionControlTmpChange and this table does not allow more than one entry for the same object. During 2nd entry for DirPartyPostalAddressView to SysVersionControlTmpChange, system throws error “The record already exists.”

Now I have the visibility to which object the problem is associated with. So I opened the AOT and went to view DirPartyPostalAddressView, compiled it and synchronized it with TFS. On synchronization it throws same error. Then I started looking to the customization done for this objects and came out with a conclusion that some incorrect customization was there. I fixed it and it was working perfectly.

Hope this piece of information will be useful for you.
You may write your comments below.