Export a PO as xml when posting

Hi Guys,

I’ve asked a similar question before but have a better understanding how everything fits together now.

Under the POST button have included:

CODEUNIT.RUN(CODEUNIT::V1XMLExport);

The CodeUnit looks like this:

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

This uses the standard XMLPORT 8000 which has the Purchase Header information.

This works great, however, the XML contains information regarding the first document in the purchase header table.

What I want it to do is export the Purchase Order information of the Purchase Order I’m viewing when I hit the Post button.

I imagine this will involve Rec. but as always my problem is knowing what variable types to set! Can anyone point me in the right direction?

Create a purchase header record. Set the appropriate filters (Document Type and No. since those are the keys) and use do a FINDFIRST. Then use that to load data into your stream.

Hi Pete Role,

We have set filter in RTC while exporting to PDF.

Use same code and pass the vaiable.

Sorry to keep bothering you with this Mo, but I still can’t quite get it to function as I’d like.

To re iterate:

RTC

Create new Purchase Order

Click post

Select Receive and click ok

When this happens an XML file is generated with just that order detail

In the Puchase Order Page I have it calling my CodeUnit which contains:

IF EXISTS (‘C:\versionone\temp\XML_CUSTOMER.XML’) THEN
ERASE (‘C:\versionone\temp\XML_CUSTOMER.XML’);

POFile.CREATE(‘C:\versionone\temp\XML_CUSTOMER.XML’);
POFile.CREATEOUTSTREAM(POStream);
Item.SetNo(ItemNo);
CLEAR(Item);
Item.SETTABLEVIEW(TempItem);
Item.SetNo(ItemNo);
Item.SETDESTINATION(POStream);
Item.EXPORT;
POFile.CLOSE;
MESSAGE(‘Export complete’);

I get errors regarding the Item when I try to compile regarding the Item, SetNo, TempItem and ItemNo and not clear what the variable structure should be, could you help me out?

What are the actual errors you are getting?

Is SetNo a function? If you want to set a filter you need to use SETRANGE or SETFILTER.

Is TempItem a variable?

Also it looks like the Item variable is actually your XMLPort which makes the code a little confusing. Generally a variable called item would refer to the Item table.

Hi Matt,

Thanks for the reply. I don’t know how else to explain what I’m trying to do … When a PO is posted I’d like XML generated with information on that Order based on the XMLPort that generates it, that’s all.

If you know a better way of achieving it that would be great.

Mohana helped me with an equivalent SAVEASPDF request but I never got it working correctly.

Try this

PurchHeader.RESET;

PurchHeader.SETRANGE(PurchHeader.“Document Type”,PurchHeader.“Document Type”::Order);

PurchHeader.SETRANGE(PurchHeader.“No.”,“No.”);

IF PurchHeader.FINDFIRST THEN;

IF EXISTS(‘C:\temp\XML_CUSTOMER.XML’) THEN
ERASE(‘C:\temp\XML_CUSTOMER.XML’);
POFile.CREATE(‘C:\temp\XML_CUSTOMER.XML’);
POFile.CREATEOUTSTREAM(POStream);
XMLPORT.EXPORT(8000,POStream,PurchHeader);

POFile.CLOSE;

Hi Mohana,

When I try to compile I get:

TableData0 Does Not Exist

The PurchHeader variable is associated with the Purchase Header table which does contain Document Type and No.

Can you check your Local Variable DataTypes are?

is your object compiling without above code?

i didnt find any mistake in my code.

Yes compiles fine.

Can you check your DataType declarations for PurchHeader and No.?

PurchHeader is Purchase Header table

No. is Purchase header Field…

where did you write the above code?

The above code is in my CodeUnit called XMLExport

The full process required is:

In the RTC, press the Post button having created an oder.

Select the receive option

Order is posted

XML for that order should be generated in the c:\temp folder

To achieve that:

In the Classic Client, under the Post button Action, calls my CodeUnit XMLExport

In that CodeUnit is the above code

When I try to compile it, I get the error:

Type conversion is not possible because 1 of the operators contains an invalid type

Code:=RecordRef

Can you tell me exactly what your No. is?

No. is a field of Purchase header table.

Did you pass any purchase header record to that codeunit?

how are you getting the Purchase header No. in that codeunit?

I know No. is a field, what I need to know is the Name and Datatype in the c/al Local Variable?

Did you pass any purchase header record to that codeunit?

All I have done is try and use the standard XMLPort 8000 for Puchase Order which contains the data I want to use.

how are you getting the Purchase header No. in that codeunit?

I’m not sure I understand that bit, I’m only using the code you have seen.

Can you show the code how you are calling Codeunit while posting?

I wrote that code in Purchase order form, onpush trigger of Post button so No. is rec.No…

I didnt declared any local variable…

as you written it in seperate codeunit you have to pass the record variable to that codeunit.

I think this is my problem i.e. the connection between them.

Under the onpush trigger of my post button I just have:

CODEUNIT.RUN(CODEUNIT::V1XMLExport);

I don’t have to use a CodeUnit, do you think it’s better to do this in the Page code?

Hi Mohana,

Cracked it again!

That was indeed my problem.

I have a tendancy to over complicate these types of things and get myself in a muddle!

I put your code in the page directly (removing the need for an extra CodeUnit) and it works brilliant.

Thank you so much again for you patience with a newbie!

Welcome Pete… [:D]

keep rocking