Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Download SQL based SSRS Report from button in pdf or Excel in dynamic CRM

Posted on by 60

I am facing issue while downloading SQL based SSRS Reports from ribbon button, Its working fine when No parameters will added, but with parameters not worked. It may be because of missing the correct way to pass parameters, currently i'm downloading report using Javascript code. Please help ?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Download SQL based SSRS Report from button in pdf or Excel in dynamic CRM

    Hi Jasdeep, i use the logic below:

        //INI
        var retrieveEntityReq = new XMLHttpRequest();
        var clientUrl = Xrm.Page.context.getClientUrl();
        retrieveEntityReq.open("POST", clientUrl + "/CRMReports/rsviewer/reportviewer.aspx", false);
        retrieveEntityReq.setRequestHeader("Accept", "*/*");
        retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        retrieveEntityReq.send("id=%7B" + reportId + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:ngdId=" + ngdId +"&p:Preview=" + preview);
        //END
    
        console.log('gerou report!');
    
        //INI
        var firstIndexOfReportSession = retrieveEntityReq.responseText.indexOf("ReportSession=");
        var x = retrieveEntityReq.responseText.indexOf("ReportSession=", firstIndexOfReportSession + 3);
        var reportSession = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
        var firstIndexOfControlId = retrieveEntityReq.responseText.indexOf("ControlID=");
        x = retrieveEntityReq.responseText.indexOf("ControlID=", firstIndexOfControlId + 3);
        var controlId = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
        //END
    
        var fileName = escape(ngdId + " - " + customer + " - v.");
    
        //Generate URL
        var url = clientUrl +
            "/Reserved.ReportViewerWebControl.axd?ReportSession=" +
            reportSession +
            "&Culture=1046&CultureOverrides=True&UICulture=1046&UICultureOverrides=True&ReportStack=1&ControlID=" +
            controlId +
            "&OpType=Export&FileName=" +
            fileName +
            "&ContentDisposition=OnlyHtmlInline&Format=PDF";
    
        console.log(url);   
    
        //Report Download
        window.location.assign(url);


  • ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: Download SQL based SSRS Report from button in pdf or Excel in dynamic CRM

    You need to pass the parameters slightly differently depending on which approach you are using .

    I did a blog about this along time ago - www.develop1.net/.../Embedding-CRM-reports-in-IFrames-using-the-CRM2011-Report-Viewer.aspx

    Also see social.microsoft.com/.../passing-parameters-to-crm-reports-through-url

    Hope this helps

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Download SQL based SSRS Report from button in pdf or Excel in dynamic CRM

    What happens if you add parameters ? Do you get an error, or are the parameters ignored ?

    Can you post an example of the request that you submit to download the report ?

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