Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create downloaded file name dynamically in SSRS reports

(0) ShareShare
ReportReport
Posted on by

Dear All,

i have Implemented the SSRS report using Fetch XML for the contact Entity.

Now i want to achieve this:

Suppose One of the Contact Record i have opened Whose ContactName is Contact-001 and when i click on the Run Report from the particular record form ( Contact-001) that SSRS report will run, Now when i export that report to the PDF format the PDF name will come as RDL Name instead of that i want to print Contact-001 as that PDF Name.

Please Suggest me on the same.

Regards,

Krishna.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: How to create downloaded file name dynamically in SSRS reports

    Hi Iswarya,

    Thanks for the suggestion.

    i will try and let you know the same.

    Regards,

    Krishna.

  • Suggested answer
    Iswarya Profile Picture
    1,347 on at
    RE: How to create downloaded file name dynamically in SSRS reports

    var reportName;
    var reportGuid;

    //you have to pass your "Autonumber here"(Contact-001->this attribute here)
    var fileName = "PDF01";
    function EmailReport() {

        try {

            debugger

            var selectedid = null;

            var reportid = null;

            var req = new XMLHttpRequest();
            

            var reportName = "Quote Report";

            var context = Xrm.Page.context;
            var serverUrl = context.getClientUrl();
            var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
            var retrieveResult = new XMLHttpRequest();


            retrieveResult.open("GET", ODataPath + "/ReportSet?$select=Name,ReportId&$filter=Name eq'" + reportName + "'", false);

            retrieveResult.setRequestHeader("Accept", "application/json");
            retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8?");
            retrieveResult.send();

            if (retrieveResult.readyState == 4 /* complete */) {
                if (retrieveResult.status == 200) {
                    var retrieved = this.parent.JSON.parse(retrieveResult.responseText).d;
                    var Result = retrieved.results;
                    if (typeof Result !== "undefined") {

                        reportid = Result[0].ReportId;
                            

                        var params = getReportingSession(reportName, reportid);

                            var newPth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=" + reportName + "&ContentDisposition=OnlyHtmlInline&Format=PDF";                     
                            window.open(newPth, "_self");
                         

                        } else {

                            Xrm.Utility.alertDialog(this.statusText);

                        }

                    }

                }


        } catch (ex) {

            throw ex;

        }

    }

    function getReportingSession(reportName, reportGuid) {
        debugger;
        reportName = "Quote Report";
        //reportGuid = "5462c1b7-c0ac-e711-8130-5065f38c1521";

        var selectedIds = Xrm.Page.data.entity.getId();

        selectedIds = selectedIds.replace('{', '');

        selectedIds = selectedIds.replace('}', '');

        var pth = Xrm.Page.context.getClientUrl() + "/CRMReports/rsviewer/QuirksReportViewer.aspx";   

        var retrieveEntityReq = new XMLHttpRequest();

        var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='quote'><all-attributes /><filter type='and'><condition attribute='quoteid' operator='eq' value='" + selectedIds + "' /> </filter></entity></fetch>";

        retrieveEntityReq.open("POST", pth, false);

        retrieveEntityReq.setRequestHeader("Accept", "*/*");

        retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:CRM_quote=" + strParameterXML);

        var x = retrieveEntityReq.responseText.lastIndexOf("ReportSession=");

        var y = retrieveEntityReq.responseText.lastIndexOf("ControlID=");

        var ret = new Array();

        ret[0] = retrieveEntityReq.responseText.substr(x + 14, 24);

        ret[1] = retrieveEntityReq.responseText.substr(x + 10, 32);

        return ret;

    }




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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans