web
You’re offline. This is a read only version of the page.
close
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 916

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 ?

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    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);

  • WillWU Profile Picture
    22,361 on at

    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.

  • ALAhmed Profile Picture
    916 on at

    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

  • Sergei Minozhenko Profile Picture
    23,093 on at

    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

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans