In this post let’s explore creating XML using X++ code in Dynamics AX.

The following example shows how to create and write data to an XML file by using the XmlDocument, XmlElement, and XmlWriter classes. It loops through all of the records in the CarTable and find all the fields in the table automatically by using the DictTable and DictField classes.

static void WriteXml(Args _args)
{

    XmlDocument xmlDoc;
    XmlElement xmlRoot;
    XmlElement xmlField;
    XmlElement xmlRecord;
    XMLWriter xmlWriter;

    CarTable carTable;
    DictTable dTable = new DictTable(tablenum(CarTable));
    DictField dField;
    int i, fieldId;
    str value;
    ; 

    #CarsXmlTags 

    // Create a new object of the XmlDocument class
    xmlDoc = XmlDocument::newBlank();

    // Create the root node
    xmlRoot = xmlDoc.createElement(#CarRootNode);

    // Loop through all the records in the carTable
    while select carTable
    {
        // Create a XmlElement (record) to hold the
        // contents of the current record.
        xmlRecord = xmlDoc.createElement(#CarRecords);
        // Loop through all the fields in the record

        for (i=1; i<=dTable.fieldCnt(); i++)
        {
            // Get the fieldId from the field-count
            fieldId = dTable.fieldCnt2Id(i);
            
            // Find the DictField object that matches the fieldId
            dField = dTable.fieldObject(fieldId);
            
            // Skip system fields
            if (dField.isSystem())
            continue;

            // Create a new XmlElement (field) and
            // have the name equal to the name of the
            // dictField
            xmlField = xmlDoc.createElement(dField.name());
            
            // Convert values to string. I have just added
            // a couple of conversion as an example.
            // Use tableName.(fieldId) instead of fieldname
            // to get the content of the field.
            switch (dField.baseType())
            {
                case Types::Int64 :
                    value = int642str(carTable.(fieldId));
                break;
                case Types::Integer :
                    value = int2str(carTable.(fieldId));
                break;
                default :
                    value = carTable.(fieldId);
                break;
            }

            // Set the innerText of the XmlElement (field)
            // to the value from the table
            xmlField.innerText(value);
             
            // Append the field as a child node to the record
            xmlRecord.appendChild(xmlField);
        }
         // Add the record as a child node to the root
        xmlRoot.appendChild(xmlRecord);
    }
    // Add the root to the XmlDocument
    xmlDoc.appendChild(xmlRoot);
    // Create a new object of the XmlWriter class
    // in order to be able to write the xml to a file
    xmlWriter = XMLWriter::newFile(@"c:tempcars.xml");
    // Write the content of the XmlDocument to the
    // file as specified by the XmlWriter
    xmlDoc.writeTo(xmlWriter);
}

The file that is created looks like the one in the following screenshot(only first part of the file is shown):

As you can see, this file is based on a standard XML format with tags and values only. You can, however, use tag attributes as well. To put the values from the table into tag attributes instead of their own tags, simply change the following code snippet in the example above

// Set the innerText of the XmlElement (field)
// to the value from the table
xmlField.innerText(value);

// Append the field as a child node to the record
xmlRecord.appendChild(xmlField);

With these lines:

// Add the attribute to the record
xmlRecord.setAttribute(dField.name(), value);

The file that is created now looks like the one in the following screenshot:

The answer is that there is no difference, the difference is a conceptual one rather than a functional or a technical one. So I think you will make a better choice for your scenario base on functional side.

Display Menu item

This folder is used to contain menu items that reference runnable application objects that primarily present forms, ddialog and so on, to the user. May be this forms, dialog called from another forms.

Output Menu item

An output menu item application objects whose primarily function is to print a result or report.

Action Menu item

You should create a menu item under this folder if your runnable application objects whose primarily function is to do some kind of a job, such as creating or updating transactions in the database.

The model store is the portion of the Microsoft Dynamics AX database where all Microsoft Dynamics AX application elements are stored, including customization. The model store replaces the AOD (application object definition) files used in previous releases of Microsoft Dynamics AX (I mean from 4.0 to 2009).

Layer and model information are integral parts of the store. The AOS has access to the model store, handles layer-flattening, and provides model data to all the Microsoft Dynamics AX sub-systems, such as form- and report-rendering and X++ code.

Microsoft Dynamics AX contains sixteen layers. Each layer consists of one or more logical parts called models. A system generated model exists for each layer.

For example, the VAR Model is the system generated model for the VAR layer. You can use the system generated models to install and start working with the base Microsoft Dynamics AX system. You can leverage the capabilities of models, and tools and functionality that support the models, during customization of the Microsoft Dynamics AX application.

  • The model store is the portion of the Microsoft Dynamics AX database where all Microsoft Dynamics AX application elements are stored, including customization.

  • The model store replaces the AOD files used in previous releases of Microsoft Dynamics AX. It can be managed through the AXUtil command line utility, or by using Windows PowerShell.

  • The baseline model store database holds model store tables for the previous version of metadata. Use it only during an upgrade.

  • The baseline model store is similar to the old folder in previous releases of Microsoft Dynamics AX.

Thank you for reading!

Understanding the internal architecture of Microsoft Dynamics AX 2012 can help you make decision when planning and developing a Microsoft Dynamics AX 2012 system. Here are some pointers on DAX 2012 architecture primarily for DAX 2012 architects & solution developers. This topic provides a high-level overview of the system architecture of Microsoft Dynamics AX.

System architecture

This diagram provides a high-level over of a Microsoft Dynamics AX 2012 system with all components installed, and describes how communications flow between the components.

* Application Object Server (AOS) architecture

This diagram describes the functionality within the AOS Windows service, and describes how communications flow within it.

![](https://dynamics365.github.io/assets/AOSWindowsService.gif)

**Note**: Clients communicate with an AOS by using remote procedure calls (RPCs), Windows Communication Foundation (WCF), or AOS services. In previous releases, other components and third-party programs could communicate with an AOS by using either .NET Business Connector or Application Integration Framework (AIF). For this release, we recommend that third-party programs use AOS services to communicate with AOS.

* Business Connector architecture

The differences between the client kernel as it runs on a standard client and a Business Connector client are:

* The Session Manager in the client kernel manages only a single instance–in the Business Connector kernel, it manages multiple instances.

* he client kernel includes forms security, while the Business Connector kernel does not.

This diagram describes the architecture of the Business Connector version of the client kernel, and describes how communications flow within it.

![](https://dynamics365.github.io/assets/Business_Connector_Client.gif)

* Application file server architecture

![](https://dynamics365.github.io/assets/App_file_server_architechture.gif)

Model store architecture

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 following table describes the application object layers in Microsoft Dynamics AX 2012:

Client architecture

This diagram describes the functionality within the client, and describes how communications flow within it.

Client/server communication

The client communicates with various Microsoft Dynamics AX components in the following ways:

  • The client uses the remote procedure call (RPC) protocol to communicate with Application Object Server (AOS). The client never accesses the database or metadata directly. AOS sends the application objects and data to the client.

  • The data layer that the client uses is based on data sources that are specified in metadata for forms and queries. In addition, any X++ code that is required to retrieve data can use the built-in language support to query and adjust data.

  • The client uses a report Web Part to interact with the report server. By calling the web services that are exposed by the report server, the report control in the Web Part displays information that is contained in Reporting Services reports. These reports can include either transnational data from the Microsoft Dynamics AX application or OLAP cubes from Microsoft SQL Server Analysis Services. Cubes provide business analytic and key performance indicators (KPIs).

  • The client provides workflow forms, alerts, and controls so that users can participate in the business process by using the Workflow system. The Workflow system is a Microsoft Dynamics AX component that enables workflow processes by using Windows Communication Foundation classes.

  • The client provides a Help viewer, which is an application that displays context-sensitive Help topics. The Help topics are retrieved from a Help server that is located on-premises.

  • The client also provides Role Centers, or role-based home pages, for users. Role Centers provide role-specific tasks, activities, alerts, reports, and business intelligence that help users increase their productivity. To interact with the Role Centers that are provided by Enterprise Portal and hosted on Internet Information Services (IIS), the client uses a browser control.

Services and AIF architecture

AX 2012 exposes its functionality through services that are based on Windows Communication Foundation (WCF) and hosted on Application Object Server (AOS). External applications and client applications on the local area network consume AX services by accessing them directly from AOS.

  • These clients and applications include AX components such as the AX client, Office Add-, and Enterprise Portal.

  • Internet-based external applications and clients access the AX services through Internet Information Services (IIS). IIS routes the incoming requests for AX services to AOS. All services requests, regardless of their origin, are handled by the WCF runtime that is hosted on AOS.

  • The AIF request preprocessor, if it is configured, can intercept the inbound request messages for custom preprocessing, such as message transforms or value substitutions. The AX service invokes the necessary business logic to process the inbound request message.

  • Similarly, the AIF response postprocessor, if it is configured, can intercept the outbound response messages for custom post-processing, such as message transforms or value substitutions. The AIF response postprocessor then returns the response to the client.

Enterprise Portal architecture

This diagram provides a logical overview of a Microsoft Dynamics AX 2012 system with an Enterprise Portal server, and also describes the various components of the Enterprise Portal architecture.

Security architecture

This following diagram provides a high-level overview of the security architecture of Microsoft Dynamics AX 2012.

Workflow system architecture

  • This following diagram provides a high-level architecture of the workflow infrastructure.

  • The workflow infrastructure consists of two components that are hosted on Application Object Server (AOS): the X++ workflow run-time and the managed workflow run-time.

Analytic architecture

The following diagram shows the Microsoft SQL Server Analysis Services cubes that are included with Microsoft Dynamics AX, and the components that are used to access them.

Reporting architecture

The following diagram illustrates the architecture of the reporting functionality in Microsoft Dynamics AX.

Thank you for reading!

I don’t know exactly how I ended up where I am. I mean, programming, and lovin’ it. Even if I’m not so good.

I’ve heard a thousand of guys telling stories like: “When I was twelve my parents bought me my first computer and I started learning on my own.” or “I won a programming contest when I was in highschool”. Great. Well done. I’ve never noticed about what coding was until I was eighteen, when I had to decide what to study at the University.

Do you want to know what was I thinking about? First option: Computer Science. Second option: Arts (wtf?). Third option: Philosophy (WTF?). I’ve ever liked computers, yes, but I’d never thought I could do that amazing things with them. I also liked maths, puzzles, things that made my brain think hard and get fun at the same time. You know, quizes, enigmas, games… The conclusion was that I wanted to do something creative, where I could put my imagination on, where I could challenge myself in order to create new stuff.

My first programming class was awful. I didn’t get nothing, and everyone seemed to be so cool on it, everyone with this big “Hello World” in their screens and a smile in their faces like ‘Yeah dude, I did it.”. I didn’t even know what to write down, or what was the teacher talking about. I was so frustrated, my first exam was… well, I don’t want to talk about my first exam.

One day, I don’t know how, something changed. Suddenly, I realized what programming was. I really abstracted my mind, I looked at it from another perspective, and it came with me so clear and so beautiful and I can not explain with words what I felt.

Was it easier from then? Not at all. In fact, I left Computer Science after the first year, with almost all the subjects passed, because there was still something that made me think I was not made for it. I was so lost, I didn’t know what to do with my life. I really liked programming, but there were so much thinks that seemed to be so far away from me. And I felt that everyone around me was going good on it, it was so frustrating that I couldn’t stand it anymore.

Then, I decided I had to change my situation because there should be something out there waiting for me. I looked for other degrees in a lot of universities.

It was. I do really love what I’m studying now, but the truth is that I think I’ve found my way. Actually, I will finish also Computer Science someday, but in a different place. And I’m still getting frustrated, of course, who doesn’t?, but I know I learned to love that frustration. Let me explain myself.

Programming is that. Is try it out thousand of times. Is try to find a mistake between a million lines of code, it’s to abstract your mind to find an answer, it’s… beautiful. I know really good programmers that honestly, I think I’ll never reach out, I have not that brilliant brain. But I keep on trying it, I’m not the best, I just love what I do.

Maybe this post is not just about programming, maybe is more about to find out what do you really love. Even if sometimes you hate it, or it makes you cry, or it makes you feel so stupid because you are not able to understand it, or if it makes you think there is a lot of people smarter than you doing the same thing better. Just… enjoy your time, fight for what you want, challenge yourself to go to the next step.