AIF Transformation of Sales Order and ASN - Custom Code in Class Library

We used the following code to meet specific requirements of transformation.

1- Sales Order Transformation


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6. using System.IO;
  7. using Microsoft.Dynamics.IntegrationFramework.Transform;

  8. namespace SalesOrderTransform
  9. {
  10.     public class Class1:ITransform
  11.     {
  12.         public void Transform(System.IO.Stream input, System.IO.Stream output, string config)
  13.         {
  14.             StreamReader sreader = new StreamReader(input);
  15.             XmlTextWriter xwriter = new XmlTextWriter(output, Encoding.UTF8);

  16.             string tagName = "SalesOrder";

  17.             string inputXml = sreader.ReadToEnd();

  18.             xwriter.WriteStartElement(tagName);

  19.             xwriter.WriteString(inputXml);

  20.             sreader.Close();

  21.             xwriter.WriteEndElement();
  22.             xwriter.Close();

  23.         }
  24.     
  25.     }
  26. }





2- ASN Transformation


  1. namespace AsnTransform
  2. {
  3.     using Microsoft.Dynamics.IntegrationFramework.Transform;
  4.     using System;
  5.     using System.IO;
  6.     using System.Reflection;
  7.     using System.Xml;
  8.     using System.Xml.XPath;
  9.     using System.Xml.Xsl;

  10.     public class AsnTrans : ITransform
  11.     {
  12.         public void Transform(Stream input, Stream output, string config)
  13.         {

  14.             Stream inputXML = File.Open(@"AsnTransform.AsnStylesheet.xslt", FileMode.Open);          
  15.             if (inputXML != null)
  16.             {
  17.                 XPathDocument document = new XPathDocument(input);
  18.                 XPathDocument stylesheet = new XPathDocument(inputXML);
  19.                 XslCompiledTransform transform = new XslCompiledTransform();
  20.                 transform.Load(stylesheet);
  21.                 XmlWriterSettings settings = new XmlWriterSettings
  22.                 {
  23.                     OmitXmlDeclaration = false,
  24.                     Indent = true
  25.                 };
  26.                 XmlWriter results = XmlWriter.Create(output, settings);
  27.                 transform.Transform((IXPathNavigable)document, null, results);
  28.                 results.Close();
  29.                 output.Close();
  30.             }
  31.             else
  32.             {
  33.                 output = input;
  34.             }         
  35.         }
  36.     }
  37. }
One the coding is done. We need to setup the transformation by using the following steps

Place the DLL to Client and Server Folders first.

1- Client Path
C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin

2- Server Path
C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin


1- Setup Tools > AIF > Manage Transform from your Development Environment. Point to the DLL from the Client Path as follows. May be different for others
C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin


2- Once its setup then go to System Administration > Services and Application Integration Framework > Outbound Ports 

Click the checkbox Transform all responses and select the appropriate transformation as defined in the development environment. 

3- Now verification is required from Batch Jobs to check the transformation. Need to check if batch jobs are running properly to ensure document outputs.



Comments

Popular posts from this blog

Export Data from AX 2012 - using DIXF (Data Migration Framework)

The virtual path maps to another application, which is not allowed