Set the name of the exported pdf file after ssrs is printed on the screen

I use the following code to print multiple ssrs on the screen, and then export to pdf, but I found that the file name of all pdf is composed of the last printed salesid:

public static void main(Args _args)
    {
        utcDateTime timeInUserTz = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), DateTimeUtil::getUserPreferredTimeZone());

        // TODO: Review the format
        str printTime = System.String::Format('{0:yyyyMMdd HH:mm}', timeInUserTz);

        CustPackingSlipJour   custPackingSlipJour = _args.record();
        CustPackingSlipTrans  custPackingSlipTransTmp,custPackingSlipTrans;
        Set                   salesIdSet = new Set(Types::String);

        while select OrigSalesId 
            from custPackingSlipTransTmp
                group by OrigSalesId
                where custPackingSlipTransTmp.SalesId == custPackingSlipJour.SalesId
                && custPackingSlipTransTmp.PackingSlipId == custPackingSlipJour.PackingSlipId
                && custPackingSlipTransTmp.DeliveryDate == custPackingSlipJour.DeliveryDate
        {
            salesIdSet.add(custPackingSlipTransTmp.OrigSalesId);
        }

        SetEnumerator enumerator = salesIdSet.getEnumerator();

        while (enumerator.moveNext())
        {
            SalesId parmSalesId = enumerator.current();

            DeliveryCreditNoteController controller = new DeliveryCreditNoteController();
            controller.parmTableRecId(custPackingSlipJour.RecId);
            controller.parmSalesId(parmSalesId);
            controller.parmReportName(ssrsReportStr(DeliveryCreditNoteReport, Report));
            controller.parmShowDialog(false);

            **controller.parmDialogCaption(parmSalesId+'_'+printTime);**

            SRSPrintDestinationSettings settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::Screen);

            controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            controller.startOperation();
        }
    }

I tried to use the

 controller.parmDialogCaption(parmSalesId+'_'+printTime)

line of code to control the exported file name, but it didn’t work, how can I modify the code to achieve my purpose

Check previous discussions on this topic. For example, look at Change file name of SSRS when export to PDF using X++, although I’m not sure that it still applies to the current application version.

By the way, most of your is not related to your current question. Please always try to use just the minimal code needed to demonstrate the problem. Unrelated code makes understanding more difficult instead of helping.

Thanks for your suggestion, I read the related posts you gave, I don’t have a reference to the class SrsReportViewerControl in my code, I don’t know how to use this class

You ask for something that the framework doesn’t support, therefore you would have to adjust the reporting framework, not just your code for running a report.
If you’re not willing to debug and adjust the reporting framework, consider it as unsupported.

How can I adjust the frame?

You asked about the code in the other discussion thread, didn’t you? And I responded. The code is an extension of the reporting framework (not a frame), namely an extension of SrsReportViewerControl class. That’s where the behavior needs to be adjusted, or at least used to at the time of writing the code.

I looked at your sample code in another post, but I don’t understand how this piece of code relates to my current report?

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

It sets the name of the exported file. Your controller could return the new file name form my_getReportViewerExportFilename() method. Feel free to ignore this solution if it’s too complicated. And if you decide to use it, test first whether it’s still applicable, because there were some changes regarding the report viewer.

Since I couldn’t apply the solution you gave, I chose to ignore, but I found another solution through the discussion in other posts, using the code below can also solve my problem

controller.parmLoadFromSysLastValue(false);