My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

24 October 2011

Printing documents linked with Document Handling while printing Reports

by Patrik Luca 2 comments

Tag



Business requirement: Printing documents linked with Document Handling while printing Reports

This post describes how you can print automatically documents linked with Document Handling while printing a Report. This post elaborates following business scenario: users attach documents to the Project entity. Upon printing the Project Invoice, these documents should be printed right away and in an automatic way.

Solution:

Add a new ProjTable variable to the classDeclaration of the Report ProjInvoice: it will be used to store the value of our currently printed Project.

Create a method on table ProjInvoiceJour to get the ProjId for the currently printed Project Invoice. In this scenario we suppose no Project Invoices are made over multiple Projects, so there is a one to one link between a Project Invoice and a Project (which is not an obligation in Dynamics AX).


display ProjId projId()
{
ProjInvoiceItem projInvoiceItem;
ProjInvoiceEmpl projInvoiceEmpl;
ProjInvoiceCost projInvoiceCost;
ProjInvoiceRevenue projInvoiceRevenue;
ProjInvoiceOnAcc projInvoiceOnAcc;
ProjId projId = '';
;

while select projInvoiceEmpl
where projInvoiceEmpl.ProjInvoiceId ==
this.ProjInvoiceId
&& projInvoiceEmpl.InvoiceDate == this.InvoiceDate
{
if (projId && projId != projInvoiceEmpl.ProjId)
return "";
projId = projInvoiceEmpl.ProjId;
}

while select projInvoiceItem
where projInvoiceItem.ProjInvoiceId ==
this.ProjInvoiceId
&& projInvoiceItem.InvoiceDate == this.InvoiceDate
{
if (projId && projId != projInvoiceItem.ProjId)
return "";
projId = projInvoiceItem.ProjId;
}

while select projInvoiceCost
where projInvoiceCost.ProjInvoiceId ==
this.ProjInvoiceId
&& projInvoiceCost.InvoiceDate == this.InvoiceDate
{
if (projId && projId != projInvoiceCost.ProjId)
return "";
projId = projInvoiceCost.ProjId;
}

while select projInvoiceRevenue
where projInvoiceRevenue.ProjInvoiceId ==
this.ProjInvoiceId
&& projInvoiceRevenue.InvoiceDate == this.InvoiceDate
{
if (projId && projId != projInvoiceRevenue.ProjId)
return "";
projId = projInvoiceRevenue.ProjId;
}

while select projInvoiceOnAcc
where projInvoiceOnAcc.ProjInvoiceId ==
this.ProjInvoiceId
&& projInvoiceOnAcc.InvoiceDate == this.InvoiceDate
{
if (projId && projId != projInvoiceOnAcc.ProjId)
return "";
projId = projInvoiceOnAcc.ProjId;
}

return projId;
}


Call this method in the fetch of the Report ProjInvoice.




...
projInvoiceTable = ProjInvoiceTable::find(
projInvoiceJour.ProjInvoiceProjId);
// BGN Get ProjId for the ProjInvoiceJour
projTable = ProjTable::find(projInvoiceJour.projId());

projFormLetterReport.loadPrintSettings(
// END
...


Create a method printLinkedDocuments in the Report ProjInvoice.




void printLinkedDocuments()
{
#WinAPI
DocuRef docuRef;
;
while select docuRef
where docuRef.RefCompanyId == projTable.dataAreaId
&& docuRef.RefTableId == tableNum(ProjTable)
&& docuRef.RefRecId == projTable.RecId
{
if(docuRef.RecId)
{
if (element.printJobSettings().getTarget() ==
PrintMedium::Printer)
{
WinAPI::shellExecute(docuRef.completeFileName(),
element.printJobSettings().printerPrinterName(),
‘’,
#ShellExePrint);
}
}
}
}


Call this method in the fetch method of the ProjInvoice Report.




...
this.printDocumentHeader();
this.send(formLetterRemarks);
// BGN Print documents linked with document handling
this.printLinkedDocuments();
// END

if (element.page() != 1)
{
...


When printing the ProjInvoice Report to a Printer, the linked documents will be printed too: the linked documents will be printed on the default Windows printer of the user.


Comments 2 comments
Gaurav Singhal said...

Thanks for this Tutorial. I am doing same functionality but with little more customized.
I need to get current printer setting of sales order invoice and awith those properties I need to print the documents.
Ex: If current invoice print setting is to print in XPS document, then print attached docs in same format.

Unknown said...

Gaurav,
In your solution do the attachments end up in the same XPS as the report or are multiple files generated?

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Blog Archive

My Blog List

Followers

Links