Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to get Report session for executing report and generate pdf from ssrs report

Posted on by Microsoft Employee

Hello,

I am new to Dynamics 365. I am trying to execute ssrs report on quote given by default using javascript. But I am unable to get response. I am getting value of index of ReportSession as -1 and ControlId as -1. When I checked response it is showing an error occured. Below is my code for getting report session.

function getReportingSession()  
{  
    var selectedIds = Xrm.Page.data.entity.getId();  
    var reportName = "Quote.rdl";  
    var reportGuid = "54f73f63-eec9-e711-8134-c4346bdcdf71"; //OR Report GUID - Replace with your report GUID  
  
    var pth = Xrm.Page.context.getClientUrl() + "/CRMReports/rsviewer/QuirksReportViewer.aspx";  
  
    var retrieveEntityReq = new XMLHttpRequest();  
  
    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");  
  
    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;  
}

Please help.

Thanks in advance.

*This post is locked for comments

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    call this function "EmailReport" in your custom button inside your form(the function from above script)to download pdf for individual record.

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    hi,

    in the same form create another custom button and call this pdf generate script in that button action , you will get particular record pdf

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    I tried this also but pdf generated shows all records of quote entity

    4403.bug.png

    Above is output when I created custom button in ribbon and triggered js webresource.

    But when I Click on Run Report -> Run Report on current record -> QuoteReport(My custom simple report)

    I get output as expected.

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    call this function in Custom button Action. to run report

    function OpenQuoteReport() {
        debugger;
        var rdlName = "QuoteWithHeader.rdl"; //Replace your report name
        var reportGuid = "6D69ABCC-0693-E711-8123-C4346BDC0E01"; //Replace your report id
        var entityType = "1084"; //Replace your entity type code(i am using my ribbon button in quote entity , so i use that code)
        var entityGuid = Xrm.Page.data.entity.getId();  
      //  var ParameterId = Xrm.Page.getAttribute("quotenumber").getValue();
        var url = Xrm.Page.context.getClientUrl() + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=" + rdlName + "&id={" + reportGuid + "}&records=" + entityGuid + "&recordstype=" + entityType;
        window.open(url, null, 800, 600, true, false, null);   
    }

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    just create custom button using ribbon workbench, call the script in that button action to run report

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    Can you tell me which button to be used to trigger javascript?

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    use ribbon button in your form, button click to run your report. to get particular record have to use prefiltering

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    Now I am able to get report session and ControlId for executing report. But when I execute and generate pdf of report, it generates report for all the records in that entity.

    Please help.

    Thanks in advance...

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Thanks for help.Will try for it

  • Suggested answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Unable to get Report session for executing report and generate pdf from ssrs report

    Hi,

    i too get same error, after follow bhart instruction luckily its works for me.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans