Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Change the filename of an SSRS report when emailed through X++

Posted on by 203

Hi

I have the following code (excerpt only, not full method) to both email a SSRS report and save it as a file:

    // create email contract
    emailContract = new SrsReportEMailDataContract();
    
    // fill in the email contract details
    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF); 
    emailContract.parmSubject("My Report"); 
    emailContract.parmTo("someone@someone.com");   
    
    // email report
    certificateController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Email);
    certificateController.parmReportContract().parmPrintSettings().parmEmailContract(emailContract);
    certificateController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    certificateController.parmReportContract().parmPrintSettings().fileName(tSaveParameters.CertificateUNCPath + '\\' +  fileNamePDF);
    
    certificateController.runReport();    
    
    // generate file for archiving
    certificateController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    certificateController.parmReportContract().parmPrintSettings().overwriteFile(true);
    certificateController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    certificateController.parmReportContract().parmPrintSettings().fileName(tMFilesParameters.FLW_MFilesCertificateUNCPath + '\\' +  fileNamePDF);

    certificateController.runReport();

When the email is received, the report as an email attachment is the AOT name of the report eg. Reportname.PrecisionDesign1.pdf

When the report is saved to a file share, it is the name I gave it.

Can I change the name of the attachment on the email, in the same way I change the name of the saved file?

Many thanks in advance!

*This post is locked for comments

  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Hi all

    Found it!

    I needed to set the parmDialogCaption of the controller class as follows

    certificateController.parmDialogCaption('EC Declaration');


  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Many thanks Ada

    I have traced it as far as this method SrsReportDataContract::parmReportName

    [DataMemberAttribute('ReportName')]
    public SRSCatalogItemName parmReportName(SRSCatalogItemName _reportName = reportName)
    {
        // if setter is called and the new report name is different than the existing name, then set the report path also.
        if(_reportName != reportName)
        {
            reportName = _reportName;
            reportPath = ''; // reset the path, so that next call to parmReportPath will get the new path.
        }
    
        return reportName;
    }

    But the variables _reportName and reportName are the same (the wrong string!).  I guess I need to set a DataMemberAttribute in the report?

  • Suggested answer
    Jie G Profile Picture
    Jie G on at
    RE: Change the filename of an SSRS report when emailed through X++
    Hi cjohnson300,
    Here is the call stack when sending a standard report BankCodaDetails.
    [c]    \Classes\SysINetMail\sendMailAttachEx                                                                  37
    [c]    \Classes\SysINetMail\sendMailAttach                                                                    16
    [c]    \Classes\SrsReportRunMailer\emailReport                                                                40
    [c]    \Classes\SrsReportRunPrinter\toEmail                                                                   36
    [c]    \Classes\SrsReportRunPrinter\printReport                                                               38
    [c]    \Classes\SrsReportRunService\runReport                                                                 43
    [c]    \Classes\SrsReportRunImpl\runReport                                                                     7
    [c]    \Classes\SrsReportRunController\runReport                                                              94
    [c]    \Classes\RdlItemTransController\main                                                                   21
  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Using AX2012 R2 CU6 and the report is a bespoke report for our organisation.

    At this point in the code, the filename is as I was hoping but I can only presume something else is overwriting it later?

    Also, within the SRSReportRunController there is a number of variables set to the name of the report, I would expect one of these to be the name of the attachment?  Does anyone know which method of which class does the actual attaching of the file and / or the sending of the email?

    54051.Capture.PNG

  • Jie G Profile Picture
    Jie G on at
    RE: Change the filename of an SSRS report when emailed through X++

    Hi cjohnson300,

    Which version of AX 2012 are you using? Which report are you sending as an attachment?

    Please check the filename( ) of the SrsPrintDestinationSettings class.

    /// <summary>
    /// Gets or sets the file name.
    /// </summary>
    /// <param name="_value">
    /// The name of the file to set; optional.
    /// </param>
    /// <returns>
    /// The current file name.
    /// </returns>
    /// <exception cref="M:Exception::Error">
    /// The directory does not exist.
    /// </exception>
    ///
    [DataMemberAttribute]
    public str fileName(str _value = fileName)
    {
        #WinAPI
        str directory;
    
        // if setter is called, then get directory and check if valid, else throw error.
        if (_value && !prmisDefault(_value))
        {
            directory = System.IO.Path::GetDirectoryName(_value);
    
            // if the directory is empty then use the users temp path.
            if (!directory)
            {
                directory = SRSPrintDestinationSettings::getTempFilePath();
    
                // create the file name by combining the temp path the filename.
                fileName = System.IO.Path::Combine(directory, _value);
            }
            else
            {
                if (printMediumType == SRSPrintMediumType::File && !System.IO.Directory::Exists(directory))
                {
                    throw error(strFmt("@SYS72247", directory));
                }
    
                // if directory is valid, then just assign the value to member variable.
                fileName = _value;
            }
    
            // if file name is changed, user may be prompted for overwriting existing file; 
            //pass false to allow this prompt to happen
            this.parmOverwriteFileIsSet(false);
        }
    
        return fileName;
    }


    You can also set a break point and debug to trace the filename.

  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Hi

    Many thanks for the suggestion, but as you can see from my later post, it didn't work for me, unless I did something else wrong?!

  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Thanks Martin.  

    As suggested, I changed the line to this:

       certificateController.parmReportContract().parmPrintSettings().fileName('myreport.pdf');


    but the email I received still has the attachment named as [report name].[Design name].pdf

    1738.tempsnip.png

    Thanks for your help!

  • Suggested answer
    Jie G Profile Picture
    Jie G on at
    RE: Change the filename of an SSRS report when emailed through X++

    Hi cjohnson300, 

    You can use 

    certificateController.parmReportContract().parmPrintSettings().fileName(fileNamePDF);


    instead of 

    certificateController.parmReportContract().parmPrintSettings().fileName(tSaveParameters.CertificateUNCPath + '\\' +  fileNamePDF);

    I have tested and confirmed that certificateController.parmReportContract().parmPrintSettings().fileName(fileNamePDF) will set the attached PDF with the filename you gave it.

  • cjohnson300 Profile Picture
    cjohnson300 203 on at
    RE: Change the filename of an SSRS report when emailed through X++

    Sorry, any one got any ideas?!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans