Question Status

Suggested Answer
Ricky Scott asked a question on 9 May 2013 11:34 PM

Greetings. I am running an AIF service (VendPaymentService) which exports an XML file with the payment information. I must convert this to a CSV format and research has shown me that I have to use a .NET Assembly to Transform do that. Microsoft has step-by-steps for creating an Inbound/Import .NET Assembly (CSV to XML), but not an Outbound/Export. I am a .NET amateur and MS's example shows how to call XML building tools and CSV reading tools, but I don't know how to build CSV building tools and XML Reading ones.

Here is the MSDN Article: msdn.microsoft.com/.../gg863930.aspx

To recap, I understand the overall concept that you build the .NET tranform and how to attach it to the AIF service but I am stuck on building the .NET Assembly itself and would like to know if anyone can provide me with help or an example of building the .NET transform from XML to CSV.

Thank you so much!

Reply
Suggested Answer
Dick Wenning responded on 10 May 2013 1:43 AM

I did csv to xml , see my project dynamicsax2012csv.codeplex.com

I think by changing the code a little bit you could do the same. it is a file stream in and file stream out.

in your case the file stream in is the xml file

Kind regards, 

Kaya Solutions

Dick Wenning

+31 6 147 989 53 

Landjuweel 5

3905 PE - Veenendaal

 

OTHER CONTACT INFORMATION

Reply
Suggested Answer
Johan Evers responded on 10 May 2013 3:58 AM

Seems AX always writes with the extension .xml

In the class AifFileSystemSendAdapter the method getNewOutFileName() has the following line:

filename = curTimestamp + #FileNameSeparatorCharacter + substr(counterText, strlen(counterText) - fileNumberMaxLength + 1, fileNumberMaxLength) + #XmlFileExtension;

So I guess the solution is to create a parameter on the outbound port to set the fileextension to something else like csv and then change the system class to use this parameter.

Do you have enough information to continue now?

Reply
Martin Dráb responded on 10 May 2013 12:08 AM

You could probably use XSLT as well…
About the assembly, it's trivial to write to write CSV; it's just a string. Parsing XML would be more difficult, but fortunately many great APIs exist, such as LINQ to XML.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Suggested Answer
Dick Wenning responded on 10 May 2013 1:43 AM

I did csv to xml , see my project dynamicsax2012csv.codeplex.com

I think by changing the code a little bit you could do the same. it is a file stream in and file stream out.

in your case the file stream in is the xml file

Kind regards, 

Kaya Solutions

Dick Wenning

+31 6 147 989 53 

Landjuweel 5

3905 PE - Veenendaal

 

OTHER CONTACT INFORMATION

Reply
Johan Evers responded on 10 May 2013 3:15 AM

Hi

As said it is quite easy to do the transform just the same way as inbound using the MS tutorial.

Something like

public void Transform(Stream xmlInput, Stream output, string configuration)

{            

   sreader = new StreamReader(xmlInput);

   swriter = new StreamWriter(output);

   //Read your input xml and transform it to something useful

   // writing out:

   swriter.WriteLine("some output");

   swriter.Close();

}

The only thing I cannot figure out is how to get another filename than .xml

So if anyone could tell me that it would be very much appreciated.

Thanks

Reply
Suggested Answer
Johan Evers responded on 10 May 2013 3:58 AM

Seems AX always writes with the extension .xml

In the class AifFileSystemSendAdapter the method getNewOutFileName() has the following line:

filename = curTimestamp + #FileNameSeparatorCharacter + substr(counterText, strlen(counterText) - fileNumberMaxLength + 1, fileNumberMaxLength) + #XmlFileExtension;

So I guess the solution is to create a parameter on the outbound port to set the fileextension to something else like csv and then change the system class to use this parameter.

Do you have enough information to continue now?

Reply