Posting / Print Purchase Order Options for *.XPS document

Hi Guys,

Hopefully a quick one …

When selecting to post and print a purchase order, once posted the dialog box pops up to name the *.xps document and save it to a desired location.

Is there a way to suppress the prompt and automatically meaningfully name the document placing it in a predefined directory?


Create a purchase order for CoolWood Technologies

Select the post and print option

Purchase Order is posted and printed

CoolWood_Technologies_invoicenumber.xps placed in a c:\temp directory without prompt

I just need a way of externally identifying the *.xps produced from an external application.

Many thanks in advance.

Do you need to in .XPS only?

If not, you can use SAVEASHTML or SAVEASXML to save the report in given path…

Hi Mohana,

Thanks as always for the reply. :slight_smile:

I am happy for it to be XML, where do I go to add it as an option? Currently it only gives me XPS as per screenshot


It is printing to XPS because your default printer is set to Microsoft XPS Document Writer in your system…

No need to use Post + Print, you can save it by posting directly

Ex:In Form 50(Purchase Order), Post button OnPush trigger after

CODEUNIT.RUN(CODEUNIT::“Purch.-Post (Yes/No)”,Rec);



Hi Mohana,

That’s fantastic, exactly what I’m after.

I tried it using the form, worked great from the Classic client, however I need this via the RTC.

I added the same code for the Purchase Order Page and got this error, can I use the same method?

Above both functions are not supported in reports which have RDLC data.

This function is not supported on client report definition (RDLC) report layouts. (From Help)

You can use SAVEASPDF or SAVEASEXCEL in RTC [;)]

SAVEASPDF could just about save my life!

ok, almost there …

I have


Question: I don’t want the PurchaseHeader to be saved but only the individual Purchase Order the user has open at that time, what would the C/AL code look like?

What format should the C/AL Local Variable be? I’ve tried them all but get a Boolean error :frowning:

Take a record variable of PurchaseHeader and Get Document type and Document No and pass that…

Sorry Mohana but that’s what I need help doing …


Works a treat, but I obviously end up with the report for all the PO’s which I don’t want, I just need the one posted.


Purchheader.GET(“Document Type”::Order,“No.”);



If it Didnt work try like

Purchheader.GET(“Document Type”::Order,“No.”);



Sounds good Mohana, what should the datatype and subtype of the PuchHeader variable be? It seems to be struggling to identify the entry …

PurchHeader is record type variable of table Purchase Header

Yes that’s what I thought … Here is my code:

PurchHeader.GET(“Document Type”::Order,“No.”);
CODEUNIT.RUN(CODEUNIT::“Purch.-Post (Yes/No)”,Rec);

PuchHeader variable has a DataType of Record and Subtype of Purchase Header

It runs great, but again poimage.pdf contains all the Orders in the Purchase Order screen and not the one I’ve posted which is the functionality I require.

Any more thoughts on a way to achieve this?

Thanks again for your time on this Mohana :slight_smile:

Try this


PurchHeader.SETRANGE(PurchHeader.“Document Type”,PurchHeader.“Document Type”::Order);
CODEUNIT.RUN(CODEUNIT::“Purch.-Post (Yes/No)”,Rec);

Mohana you are the man! Thank you so much :slight_smile: