Walkthrough: Transforming a document


This content is archived and is not being updated. For the latest documentation, see Microsoft Dynamics 365 product documentation. For the latest release plans, see Dynamics 365 and Microsoft Power Platform release plans.

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

This walkthrough describes how to use a transform in an inbound port to reformat an incoming sales order request to work with the Microsoft Dynamics AX sales order service.

For this scenario, the incoming request is an XML-based document. In a previous walkthrough, the inbound document was already formatted to comply with the Microsoft Dynamics AX sales order schema. In this walkthrough, you create a different inbound document that uses a custom schema. You will then provide an Extensible Stylesheet Language Tranformation (XSLT) to map the elements from the inbound document to the elements that are required by the sales order schema. Finally, you will submit the incoming document to Application Integration Framework (AIF) and view the results.


Creating the sales order request

For this scenario, the incoming sales order request document, the internal sales order, uses the following Extensible Stylesheet Definition (XSD) schema. You do not need to save a copy of this schema. It is presented here for your information.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://InternalSalesOrder" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="SalesOrder">
        <xs:element name="Header">
              <xs:element name="CustAccountNum" type="xs:string" />
              <xs:element name="DateReq" type="xs:date" />
              <xs:element name="OrderDate" type="xs:date" />
              <xs:element name="PONum" type="xs:string" />
        <xs:element name="Items">
              <xs:element name="Item">
                    <xs:element name="ID" type="xs:string" />
                    <xs:element name="Qty" type="xs:nonNegativeInteger" />
                    <xs:element name="Unit" type="xs:string" />

The following XML code creates an example of a document that complies with the XSD for the internal sales order. Save a copy of this file and name it InternalSO.xml.

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="InternalSO.xslt"?>
<ns0:SalesOrder xmlns:ns0="http://InternalSalesOrder">

You must modify the internal sales order document:

  • Provide values that work in your test environment. For example, provide valid values for <CustAccountNum> and <ID>.

  • Provide a unique GUID value for <MessageId>.


This scenario assumes that the internal sales order request contains a message ID that is formatted as a GUID. If your actual internal document does not contain a message ID, you may want to generate your own GUID. The value cannot be generated by XSLT, so you must provide some other facility to preprocess your source document to create the message ID. If you do not provide a message ID, one will be created for you by AIF and it will be included in the response message. However, because this interaction is asynchronous, you will not be able to use the AIF value to match response messages to request messages.

Creating the transform

For this scenario, use the following XSLT code. Copy the code to Notepad and name the file InternalSO.xslt when you save it.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  <xsl:template match="InternalSO:SalesOrder">
    <Envelope xmlns="https://schemas.microsoft.com/dynamics/2011/01/documents/Message">
          <xsl:value-of select="Header/MessageId"/>
          <SalesOrder xmlns="https://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder">
            <SalesTable class="entity">
                <xsl:value-of select="Header/CustAccountNum"/>
                <xsl:value-of select="Header/DeliveryDate" />
                <xsl:value-of select="Header/PONum" />
                <xsl:value-of select="Header/DateReq" />
              <SalesLine class="entity">
                  <xsl:value-of select="Items/Item/ID" />
                  <xsl:value-of select="Items/Item/Qty" />
                  <xsl:value-of select="Items/Item/Unit" />

The previous XSLT above this paragraph uses a template to create the AIF message envelope and then maps the elements that are contained in the internal sales order document to the elements that are required by the Microsoft Dynamics AX sales order schema. (Recall that, in the previous walkthrough, the sales order schema that was used by the inbound port was specified in the Document data policies form.) The XSLT adds the <Action> element to specify the create action for the sales order.

Add the transform

To use the transform, you first must add the transform file to the list of available transforms by using the Manage transforms form.

  1. Click System administration > Setup > Services and Application Integration Framework > Inbound ports.

  2. Deactivate the integration port named SalesOrderCreate, if it is still active. (You created this integration port in the previous walkthrough.)

  3. Click Inbound transforms. Then, on the Action Pane, click Manage transforms.

  4. Click New.

  5. In the Name field, type the name, InternalSO. Optionally, enter a description.

  6. In the Type list, select XSL.

  7. Click Load.

  8. In the Open dialog box, change the file specification to XSLT files. Browse to the file that you named InternalSO.xslt. Click Open to load the file.

    You can view the XML code in the Content text box.

  9. Close the form to save the new transform.

Configure the integration port

Add the inbound transform to the integration port.

  1. In the Inbound transforms form, click New.

  2. In the Transform name list, select InternalSO.

  3. Activate the port.

  4. Close the forms.

Send the request and view the response

Because this scenario uses the integration port that you created in Walkthrough: Exchanging documents by using the file system adapter, you will use the same directories for inbound and outbound communication.

  1. Save a copy of the file that you named InternalSO.xml to the folder named AIFIn.

  2. Wait for the batch job to retrieve the file from the folder.

  3. Watch the folder named AIFOut. After several minutes, AIF will save a response file to this folder.

  4. Open the response file to view the XML code.

See also

Walkthrough: Exchanging documents by using the file system adapter