web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
Answered

Button Click Download Report as Pdf Format

(0) ShareShare
ReportReport
Posted on by 1,347

Hi,

  i am working on Dynamics 365 online , i have to download custom report as pdf format on Button click how to achieve this please guide me to do this.

Thanks and Regards,

Iswarya.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    simply click on the save button and then you get a list of export file types:

    2017_2D00_09_2D00_07-12_5F00_54_5F00_21_2D00_Report-Viewer_5F00_-Sales-History.png

    Best

  • Iswarya Profile Picture
    1,347 on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    By doing a single click, I need to generate a report in the PDF format through custom ribbon button? I would be grateful, if anyone could provide the viable script to accomplish this functionality

  • Community Member Profile Picture
    on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    okay then it is quite trickier as you will need to find all the actions that triggers your specific report, then aggregate the results and finally export it to a certain format.

    If you find a solution, I would gladly see it :)

  • Iswarya Profile Picture
    1,347 on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    By doing a single click, I need to generate a report in the PDF format through custom ribbon button and I would be grateful, if anyone could provide the viable script to accomplish this functionality

  • Community Member Profile Picture
    on at
    RE: Button Click Download Report as Pdf Format

    Hi Iswarya,

    I too got the same requirement, did you got any solution?

    Regards,

    sreekanth

  • Suggested answer
    Iswarya Profile Picture
    1,347 on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    yes, see this

    community.dynamics.com/.../253073

  • Verified answer
    Iswarya Profile Picture
    1,347 on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    this is my code

    var reportName;

    var reportGuid;

    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;

    }

  • Suggested answer
    ARIFNIIT Profile Picture
    1,391 on at
    RE: Button Click Download Report as Pdf Format

    Just open specific report on button click. user can download report as PDF by clicking on inbuilt pdf button.

    open  report  using Script

    function OpenReport(){

    var url = Xrm.Page.context.getClientUrl() + "/crmreports/viewer/viewer.aspx?action=run&helpID=" + rdlName + "&id={" + reportGuid + "}"

    window.open(url, null, 800, 600, true, false, null);

    }

    click on button PDF file.

    2017_2D00_09_2D00_07-12_5F00_54_5F00_21_2D00_Report-Viewer_5F00_-Sales-History.png

  • Suggested answer
    Iswarya Profile Picture
    1,347 on at
    RE: Button Click Download Report as Pdf Format

    Hi,

    which version r u working?? based on version have to change this path

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

    let me know your version, then i will provide correct path

  • ARIFNIIT Profile Picture
    1,391 on at
    RE: Button Click Download Report as Pdf Format

    Are you using 9.0 or higher? so you can use QuirksReportViewer to open Reports.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans