SAVEASXML in the RTC

Hi Guys,

I realise SAVEASXML is not supported in the RTC, but let’s assume you do want a report in this form and can only use the RTC, how would one achieve it?

I have a requirement that when the post button is pressed on the Purchase Order screen within the RTC, an XML file with the information therein is produced so an external program can read it and perform relevant actions based on it’s contents.

I already have a PDF created, (big thanks to Mohana for that) but the requirement is an either or scenario.

Check the xml file format of classic report how it is exported and create a xml port to for xml file from RTC…

Hi Mohana,

That’s what I figured.

I’m using the XMLPORT 8000 for Purchase Order

I have a CodeUnit I’ve created to export:

IF NOT EXISTS (‘c:\temp\Path.xml’) THEN
ERROR (‘xml document file does not exist’);
testfile.OPEN(‘c:\temp\Path.xml’);
testfile.CREATEOUTSTREAM(filestr);
XMLPORT.EXPORT(8000, filestr);// you can change to export
testfile.CLOSE;
MESSAGE(‘Done’);

Which compiles fine.

I’d like the data to export when posting, so under the POST button beneath the existing code on the Purchase Order Page enter

CODEUNIT.RUN(CODEUNIT::V1XMLExport);

But get this error

What do you think?

What error you are getting?

Try something like this

IF EXISTS (‘C:\Item.XML’) THEN
ERASE (‘C:\Item.XML’);

TestFile.CREATE(‘C:\Item.XML’);
TestFile.CREATEOUTSTREAM(TestStream);
Item.SetNo(ItemNo);
CLEAR(Item);
Item.SETTABLEVIEW(TempItem);
Item.SetNo(ItemNo);
Item.SETDESTINATION(TestStream);
Item.EXPORT;
TestFile.CLOSE;
MESSAGE(‘Export complete’);

If you click this link as per previous post.

If you think I can achieve this editing the Page rather than referring to a new XMLPort / CodeUnit I would prefer that.

As a comparative novice the problem I always have with C/AL code is knowing the variable declarations.

TestFile = File

TestStream = OutStream

What are the Item and SetNo declarations?

I just gave an example with Item table…

You have to use Purchase Header XML port inplace of Item.

Hi Mohana,

I’ve simplified it still further, works great!

POFile.CREATE(‘C:\temp\XML_CUSTOMER.XML’);
POFile.CREATEOUTSTREAM(POStream);
XMLPORT.EXPORT(8000,POStream);
POFile.CLOSE;

This works for an individual order and just what I want, ideally I’d like it to work for a batch of Orders as well, i.e. on the Purchase Order List page and press Post Batch … you get an XML file containing all orders therein. Can this be achieved from within the CodeUnit?

How you are calling XMLport?

Page to Codeunit to XMLPort…?

Hi Mohana,

Yes that’s exactly right, managed to crack it, thanks again!

I am very Happy that you got exactly what you want [:D]