Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

SRSPrintDestinationSettings duplicate PDF file

(0) ShareShare
ReportReport
Posted on by 912

Hi Everyone,

I created a job to save free text invoices to PDF using SRSPrintDestinationSettings in a specific folder.

This is working fine. but, the issue is that create new sub-directory with a duplicate pdf file into this new folder

static void AAl_printFreeTextInvoice2(Args _args)
{
    SalesFormLetter                 salesFormLetter;
    SRSPrintDestinationSettings     settings;
    FreeTextInvoiceContract         freeTextInvoiceContract   = new FreeTextInvoiceContract();
    FreeTextInvoiceController       freeTextInvoiceController = new FreeTextInvoiceController();
    Args                            args = new Args();
    CustInvoiceJour                 CustInvoiceJour;
    ;

    select  CustInvoiceJour where  CustInvoiceJour.recid == 5637255489;
    args.record(CustInvoiceJour);
    args.parmEnumType(enumNum(PrintCopyOriginal));
    args.parmEnum(PrintCopyOriginal::Original);
    // Set the report data contract with parameters.
    freeTextInvoiceContract.parmCustInvoiceJourRecId(CustInvoiceJour.RecId);
    freeTextInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());

    freeTextInvoiceController.parmArgs(args);
    freeTextInvoiceController.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesFreeTextInvoice).getDefaultReportFormat());
    freeTextInvoiceController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    freeTextInvoiceController.parmShowDialog(false);
    freeTextInvoiceController.parmReportContract().parmRdpContract(freeTextInvoiceContract);

    freeTextInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    freeTextInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    freeTextInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);
    freeTextInvoiceController.parmReportContract().parmPrintSettings().fileName(@"C:\Users\xxx\Desktop\xxx\Tests\freeTextInvoice.pdf");

    settings = freeTextInvoiceController.parmReportContract().parmPrintSettings();
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::FreeTextInvoice);
    salesFormLetter.parmShowDialog(false);
    salesFormLetter.updatePrinterSettingsFormLetter(settings.pack());
    salesFormLetter.parmUseUserDefinedDestinations(true);

    args.caller(salesFormLetter);
    freeTextInvoiceController.parmArgs(args);
    freeTextInvoiceController.startOperation();
}

The job save pdf and sub folder like this : 

2020_2D00_11_2D00_17_5F00_19_2D00_31_2D00_36.png

Can someone please point how can i solve this issue ?

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: SRSPrintDestinationSettings duplicate PDF file

    Hi Alex,

    I would make several modifications to achieve the goal instead of deactivating code.

    1. Add new parm member to class SrsPrintMgmtExecutionInfo and FreeTextInvoiceContract and fill new parameter in contract in job.

    2. Modified FreeTextInvoiceController.preRunModifyContract to fill new parameter in SrsPrintMgmtExecutionInfo from FreeTextInvoiceContract.

    3. Modify PrintMgmtReportRun.setPrintDestinationFileName to check new parameter from SrsPrintMgmtExecutionInfo and exit method before try-catch statement

    4. Modify SRSReportRunPrinter.toFile method to check if new parameter from SrsPrintMgmtExecutionInfo and skip copy of a created file to an original file location

     

  • ALAhmed Profile Picture
    912 on at
    RE: AX 2012 R3 SRSPrintDestinationSettings duplicate PDF file

    Thank you for your  quick reply.

    When i use this :  salesFormLetter.parmUseUserDefinedDestinations(false);  it print report on the screen, it's not save as pdf on the specific path.

    Yes, it create the new directory from the method  Classes\PrintMgmtReportRun > setPrintDestinationFileName(), I don't know what the impact of disactivating this code, i think this method is used from many report not only for freeTextInvoice

    pastedimage1605688515330v1.png

    Is there another way to save this report to PDF without using the class SalesFormLetter to pack print management ?  because the method  classes\PrintMgmtReportRun > setPrintDestinationFileName()  is called from the  method  classes\SalesFormLetter > excute() 

    pastedimage1605689171485v2.png

    Thank you in advance

  • WillWU Profile Picture
    22,352 on at
    RE: AX 2012 R3 SRSPrintDestinationSettings duplicate PDF file

    Hi Alex,

    For print management, the same print settings (that have the same file name specified) will be applied to multiple report execution like for account 1001, 1002, 1003.  In this case, the file will be overwritten multiple times and the output from previous execution will be lost.  Therefore, it will create a new directory and copy over the file to the new location to keep all the outputs.  The new directory format will be like %UserId%-%ReportName%-%TempFileName%.

    Please go to Classes\PrintMgmtReportRun and check the setPrintDestinationFileName method.

    Also see the old thread:

    dynamicsuser.net/.../saving-in-po-on-disk-in-pdf

    And you can try Sergei's code.

    Hope this helps.

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: AX 2012 R3 SRSPrintDestinationSettings duplicate PDF file

    Hi Alex,

    I suspect that it could be related to print management set up.

    Could you try to disable print management by line below?

    salesFormLetter.usePrintManagement(false);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans