If you have a need to save reports to Print archive using dynamic filenames and not the default ones (which are fixed), you can achieve this by using Docentric AX Free Edition. Let’s demonstrate this on the Purchase order report. The built-in Print archive is very limited but changing the Description field of an archived Purchase order to contain Purch ID and Vendor Account, e.g. Purchase order 2018-044 Vendor US-006, you will at least get the ability to search Print archive by purchase ID and vendor.
Changing Description in Print archive of an archived report
Set up first in Accounts payable -> Setup -> Forms -> Form setup the built-in Print archive as the target print destination and run the Purchase order report from the Purchase order confirmation form by clicking the Use print management button. Purchase order will be saved to Print archive with Description PurchPurchaseOrder.Report. This is the default behavior.
Afterwards, set up in Accounts payable -> Setup -> Forms -> Form setup Docentric’s Print archive as the target print destination and run the Purchase order report from the Purchase order confirmation form again by clicking the Use print management button. This time Purchase order will be saved to Print archive with Description Show purchase order. This is actually the report caption that is inferred from the report menu item label.
If we want to change this from Show purchase order to something else, we can change the default report caption in Docentric report setup. In order to achieve this we need to register the PurchPurchaseOrder.Report SSRS report design in Docentric report setup first, or you can download and install Docentric SSRS Replicas instead.
You can see the whole process on the images below.
How to make Description in Print archive dynamic
Still, this report caption which overrides the built-in report caption would be useless if we cannot make it dynamic, i.e. to contain some report specific information. For example, in case of the Purchase order report this would be Purch ID, Vendor Account, etc.
We can achieve this by using a custom Docentric’s DSP class for placeholders (see below). If you are using Docentric SSRS Replicas, you will also need to add X++ code in the overrideReportRunSettings() method to replace all placeholders in the report caption, if any of them is set.
A Custom DSP class for replacing placeholders in print destinations and report caption
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
class DocPurchPurchaseOrderReportDSP extends DocDataSourceProviderSrsProforma { PurchTable purchTable; str placeholder_purchId; str placeholder_purchOrderDocNum; date placeholder_purchOrderDate; str placeholder_vendName; protected void onSelectedRdpTableRecord(Common _rdpTableRecord, TableName _rdpTableName) { super(_rdpTableRecord, _rdpTableName); if (_rdpTableName == tableStr(PurchPurchaseOrderHeader)) { PurchPurchaseOrderHeader header = _rdpTableRecord; // Store custom placeholders' values. placeholder_purchId = header.PurchId; placeholder_purchOrderDocNum = header.PurchOrderDocNum; placeholder_purchOrderDate = header.PurchOrderDate; placeholder_vendName = header.VendName; purchTable = PurchTable::find(header.PurchId); } } [DocPlaceholderAttribute('PurchId', 'PO - Purch ID'), DocPlaceholderAttribute('PurchOrderDocNum', 'PO - Document Number'), DocPlaceholderAttribute('VendAccount', 'PO - Vendor Account ID'), DocPlaceholderAttribute('VendName', 'PO - Vendor Name')] public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext, boolean _replaceStandardPlaceholders = true) { // List of defined custom placeholders for the report: #define.PurchId('PurchId') #define.PurchOrderDate('PurchOrderDate') #define.VendAccount('VendAccount') #define.VendName('VendName') DocPlaceholderManager placeholderMng = super(_reportRunContext, _replaceStandardPlaceholders); str newReportCaption = DocPlaceholderManager::replacePlaceholder( _reportRunContext.parmReportCaption(), #PurchId, placeholder_purchId); if (newReportCaption != _reportRunContext.parmReportCaption()) { _reportRunContext.parmReportCaption(newReportCaption); } // -- Placeholder @PurchId@ placeholderMng.replacePlaceholderInCurrentPrintDest(#PurchId, placeholder_purchId); // -- Placeholder @PurchOrderDate@ placeholderMng.replacePlaceholderInCurrentPrintDest(#PurchOrderDate, placeholder_purchOrderDate); // -- Placeholder @VendName@ placeholderMng.replacePlaceholderInCurrentPrintDest(#VendName, placeholder_vendName); // -- Placeholder @VendAccount@ str vendAccount = purchTable.OrderAccount; placeholderMng.replacePlaceholderInCurrentPrintDest(#VendAccount, vendAccount); // Change the report execution context to the corresponding PurchTable record. _reportRunContext.setReportExecutionContextRecord(purchTable); return placeholderMng; } } |
Advanced control of both Description and Filename in Print archive
By default, the filename and description of an archived report look the same. But if you need them to be different, or you don’t want to use Report caption to make archived report names dynamic, you can use the following event handlers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, printToArchiveChangeArchiveFilename))] public static void DocReportRunDelegates_printToArchiveChangeArchiveFilename(DocPrintReportSettings _printReportSettings, DocEventHandlerResult _result) { if (_printReportSettings.parmReportId() == ssrsReportStr(PurchPurchaseOrder, Report)) { PurchTable purchTable = _printReportSettings.getReportExecutionContextRecord(); _result.result(strFmt('PO %1 VA %2.pdf', purchTable.PurchId, purchTable.OrderAccount)); } } [SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, printToArchiveChangeArchiveDescription))] public static void DocReportRunDelegates_printToArchiveChangeArchiveDescription(DocPrintReportSettings _printReportSettings, DocEventHandlerResult _result) { if (_printReportSettings.parmReportId() == ssrsReportStr(PurchPurchaseOrder, Report)) { PurchTable purchTable = _printReportSettings.getReportExecutionContextRecord(); _result.result(strFmt('Purchase order: %1, Vendor account: %2', purchTable.PurchId, purchTable.OrderAccount)); } } |
The results you can compare on the images below.