Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Replicate JS function of creating email with SSRS report in workflow

Posted on by Microsoft Employee

I am trying to attach a SSRS report in a prepopulated email and send it. In order to do this, am trying to mimic a JS function which creates a new email with the PDF button attached on click.
What is thr equivalent of the following JS code in C#?

var reEntReq = new XMLHttpRequest();
reEntReq.open("POST", pth, false);
reEntReq.setRequestHeader("Accept", "*/*");
reEntReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

reEntReq.send(query);
//These variables captures the response and returns the response in an array.
var x = reEntReq.responseText.lastIndexOf("ReportSession=");
var y = reEntReq.responseText.lastIndexOf("ControlID=");
var ret = new Array();
ret[0] = reEntReq.responseText.substr(x + 14, 24);
ret[1] = reEntReq.responseText.substr(x + 10, 32);

*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    My suggestion - open reporting services instance and clarify all the details you need - report name, parameters e.t.c. Reports in reporting services contain all information you need.

    Good luck.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Hi Andrew,

    Sorry for my late response. You were right. I was using the wrong URL. So my server url looks something like this :

    http://Server Name/ReportServer/ReportExecution2005.asmx

    servername/.../ReportViewer.aspx

    My report is the same as the blog post which you posted. It is a Quote Report which takes the Quote GUID. The second URL I mentioned is the final path of the report where I will enter the GUID of the Quote.

    parameters[0].Value = string.Format("Select * From FilteredQuote Where QuoteId = '{0}'", context.PrimaryEntityId);

     byte[] reportresult = rg.Render("/contoso_mscrm/quote", FormatType.PDF, parameters);

    What should I do about the above two lines? Since it is taking in Quote ID , will the same query apply in my case as well?(Select * From FilteredQuote Where QuoteId = '{0})?

    And this line -  " byte[] reportresult = rg.Render("/contoso_mscrm/quote", FormatType.PDF, parameters)"? What should I be changing it to in my case? I mean I am confused about the path I need to enter.Can you think of what it might be in perspective of my server path and the report path I mentioned above? I would be needing it in a PDF Format.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Hello,

    I believe you use wrong url during adding of web reference.

    Take a closer look on following screenshot from my article - 4.bp.blogspot.com/.../93.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    ReportExecutionService _reportexecutionservice = null;

    The above part. I believe you should be adding a web reference to the reporting web service? If I try to add it , I am thrown a " Object doesn't support addEventListener" error.

    Currently my reports are in the URL, "organization url/crmreports/viewer/viewer.aspx?action=filter&helpID=Report Name &id=%7b ReportId %7d.

    However, the JS function which am trying to mimic, has this URL referenced as report server : "Organization url/CRMReports/rsviewer/QuirksReportViewer.aspx";

    The query it is executing is : "id=%7B" + reportGuid +

           "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName()

           + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName

           + "&isScheduledReport=false&p:QuoteId=" + reportPrefilter;

    I am confused as to which URL I need to be using. I tried both the URLs and both are throwing me errors..I am currently on on -premise 2016. My reports are published for external use.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    If you're onprem - what doesn't work when you try to use my article. I believe this one - butenko.pro/.../ms-crm-2011-general-approaches-to-generation-of-reports

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Ok for trying to mimic the JS function ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Mine is on premise only.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    If you are online - you will not achieve that. If you're onprem - you're ok.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Hi Andrew,

    I am trying to attach a PDF to a pre populated email. I am trying to follow the method mentioned in your blog. In order to do that, I need to add a web reference to

    the report server? When I try to do that am thrown the error "Object doesn't support property or method 'addEventHandler'.

    So I tried to mimic the JS method currently in the system. Looks like that would fail as well because of authentication?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Replicate JS function of creating email with SSRS report in workflow

    Hi Venky,

    Thanks for the response. What about this part?

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

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

    var ret = new Array();

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

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

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans