Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Change file name of SS...
Finance forum
Suggested answer

Change file name of SSRS when export to PDF using X++

Posted on by 35

Hi all,

i am developing on D365FO, i want to set file name of SSRS when export to PDF.

I tried to use "this.parmReportRun().parmReportContract().parmReportCaption("Caption in Runtimes");" in prePromptModifyContract() method of  SrsReportRunController. But it was not worked.

After export to PDF, the file name of SSRS still be the label of Menu Item which call controller.

My code to set report caption:

protected void prePromptModifyContract()
{
super();
this.parmReportRun().parmReportContract().parmReportCaption("Caption in Runtimes");
}

Resutl is image below:

2019_2D00_08_2D00_13_5F00_12_2D00_20_2D00_24.png

Please tell me what i can do to change the file name with code x++.

Thanks

  • SukhvirSingh Profile Picture
    SukhvirSingh 10 on at
    RE: Change file name of SSRS when export to PDF using X++

    I have tried this code but the method mentioned is not called.

    Any other suggesion please

  • SukhvirSingh Profile Picture
    SukhvirSingh 10 on at
    RE: Change file name of SSRS when export to PDF using X++

    I tried above code but it is not calling this method? Any suggestion

  • Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Change file name of SSRS when export to PDF using X++

    Your code contains extra line spaces because you didn't paste in the right way. Please use Insert > Code in the rich-formatting view.

  • Suggested answer
    Sharoze Khawar Profile Picture
    Sharoze Khawar 10 on at
    RE: Change file name of SSRS when export to PDF using X++

    You can change the PDF file name with any text through below code. I've replaced it with Invoice id. Read comments to replace it with any custom text

    [ExtensionOf(classStr(SrsReportRunController))]

    final class MySrsReportViewerControl_Extension

    {

       public LabelType parmDialogCaption(LabelType _dialogCaption)

       {

           LabelType           reportDialogCaption;

           Args                    args;

           CustInvoiceJour  custInvoiceJour;

           Name                  rdpName;

           reportDialogCaption = next parmDialogCaption(_dialogCaption);        

           if (this.getReportContract().parmRdpName() == 'Define your DP class name here')

           {

               args = this.parmArgs();

               custInvoiceJour = args.record();

               if(custInvoiceJour)

               {

                   reportDialogCaption = strFmt('%1', custInvoiceJour.InvoiceId); // Set the file name

               }

           }

           return reportDialogCaption;

       }

    }

  • Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Change file name of SSRS when export to PDF using X++

    SrsReportPdfViewerControl determines the file name in exportViewerReport() method:

    str fileName = controller.parmDialogCaption() ? controller.parmDialogCaption() : controller.parmReportName();

  • Nishi Gupta Profile Picture
    Nishi Gupta 200 on at
    RE: Change file name of SSRS when export to PDF using X++

    this worked perfectly , but now I facing another issue . the testing team seems to use embedded PDF viewer where my code fails . And putting the same code to the SrsReportPdfViewerControl extension does not help . any suggestions on that ?

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,971 Super User 2024 Season 2 on at
    RE: Change file name of SSRS when export to PDF using X++

    I've made such a modification and it wasn't trivial. Here is my code:

    [ExtensionOf(classStr(SrsReportViewerControl))]
    final class My_SrsReportViewerControl_Extension
    {
        // We can't simply refer to the standard 'viewerContract' variable,
        // because it's private.
        private SrsReportDataContract currentViewerContract;
        
        public SrsReportDataContract parmViewerContract(SrsReportDataContract _viewerContract)
        {
            if (currentViewerContract != _viewerContract)
            {
                SysOperationDialog sysOperationDialog = Dialog::getDialogFromCaller(this.formRun()) as SysOperationDialog;
                if (sysOperationDialog)
                {
                    SrsReportRunController controller = sysOperationDialog.controller();
                    if (controller)
                    {
                        // Modifies the filename when exporting from report viewer control.
                        str filename = controller.my_getReportViewerExportFilename();
                        if (filename)
                        {
                            _viewerContract.parmReportCaption(filename);
                        }
                    }
                }
            }
            currentViewerContract = _viewerContract;
            return next parmViewerContract(_viewerContract);
        }
    }

    In my notes, I also have the following remark: It would have been simpler if a half of things in the report viewer wasn't private. :-)

  • Suggested answer
    Sumit Loya Profile Picture
    Sumit Loya 2,230 on at
    RE: Change file name of SSRS when export to PDF using X++

    Try moving the code call to before super and check.

  • Nishi Gupta Profile Picture
    Nishi Gupta 200 on at
    RE: Change file name of SSRS when export to PDF using X++

    I am also facing this requiremnt  .. any solution ?

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Change file name of SSRS when export to PDF using X++

    Hi Nguyen,

    Have you created a Controller class for your report and get any error?

    After that ,did you run the incremental CIL?

    You can refer to the defined classes in AOT.

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,115 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,971 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans