blog11

Introduction:

Microsoft Dynamics AX 2012 Application Integration Framework(AIF) allows you to integrate your  Microsoft Dynamics AX 2012 application with the external applications using services by exchange of data using formatted XML. Microsoft Dynamics AX 2012 allows you to format these XML messages in a way you like using Transforms.

All the messages are stored in the gateway queue within AX before they can be processed by any service operation. The gateway queue has this limitation that it can only accept XML messages. So, it is quite possible that the third party application with which Microsoft Dynamics AX 2012 is communicating with does not understand XML. Rather it sends the data in the csv format. In that case, you would have to convert that csv into the valid XML for Microsoft Dynamics AX 2012. In all of these scenarios you could make use of a transform.

Transforms are of two types:

  • XSLT
  • .Net Assembly

In this post, we ‘ll be focusing on XSLT and we will see how we can create a simple transform using XSL.

What is XSL?

XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents. XSLT stands for XSL Transformations. So if you are an XML guy, you can make use of XSLT within Microsoft Dynamics AX very easily.

Let’s consider the example of outbound Sales Invoices.

At present, the format of the output XML message is:

<Envelope>

//more XML tags….

</Envelope>

But, what we want is that the header tag should tell us the name of document. So our expected output XML is:

<SalesInvoice>

//more XML tags….

</SalesInvoice>

So, as you can see that we want to replace the <Envelope> tag with a more meaningful document specific <SalesInvoice> tag. This would enable the third party application understand that this is a Sales invoice message by merely processing the header tag. Now we ‘ll create a transform using XSL that would render us the output xml in the required format.

So this is the XSL code that would enable us to achieve the required format:

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:a=”http://schemas.microsoft.com/dynamics/2011/01/documents/Message”>

  <xsl:output method=”xml” omit-xml-declaration=”no”/>

  <xsl:template match=”@*|node()”>

    <xsl:copy>

      <xsl:apply-templates select=”@*|node()”/>

    </xsl:copy>

  </xsl:template>

  <xsl:template match=”a:Envelope”>

    <xsl:element name=”SalesInvoice”>

      <xsl:apply-templates select=”@*|node()”/>

    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

 Steps to add the XSL transform to our Sales Invoice service

1. Create an inbound port for our service. Select file system adapted and provide a valid file directory where the output xml would be written.blog11

2. Click on Service operations and select the Read operation for the Sales invoice service.

blog2

3. In your outbound port form, select the “Transform all responses” check box and click “Outbound Transforms” button.

blog21

4. A form would open up, then click new and click on this button in the action pane called “Manage transforms”.

blog4

5. Another form would open up, click new and provide any name. Next select “XSL” in the type. And click “Load” button. Then locate and select your “XSLT” file and click Open.

blog5

6. As you can see that the “XSLT” is loaded into this text box.

blog6

7. Now close this form. Select this newly created transform now in the enhanced outbound transform form.

blog7

8. We are all done now. Now to test, open up your Sales invoice journal form. Click “Send” and select “Original”. This would trigger the Sales invoice service read operation.

blog8

9. Now navigate to the directory you provided in the Outbound port. Your transformed xml message should like this:

blog_11

To run the outbound services demo using file adapter, please make sure that the Batch server is configured and that the batch jobs necessary for gateway execution are running. For more details about those jobs, please visit this link : http://technet.microsoft.com/en-us/library/hh352328.aspx

Leave a Reply

Recent Comments

    Archives

    Categories