Generating reports in CRM 2011 is cool. Exporting a report as PDF is great. Attaching the PDF version of a report to a record or an email is a lot of clicks. Automating the process is actually quite easy, for an On Premise installation that is. With on premise, you have access to your report server and you can execute .Net code in any way you want. So hooking up the Reporting Services web services and CRM Web services in a single program makes it very easy to stream a report as a PDF and attach it to a CRM record. But when you try and do that in CRM online, you hit a couple of issues: You do not have access to Microsoft's report servers, nor can you run any .Net code wherever you want (unless you have a spare Windows Azure account). So how do we attach a report to a CRM record? You have to perform the following tasks:
1. Initiate a report session to get some session id's
2. Use these id's to request a report in pdf format
3. Convert the binary output to a base64 encoded string
4. Create a new annotation, and "attach" the encoded pdf file.
It took me a couple of hours to get through these tasks, mainly because Internet Explorer is stubborn.
Since CRM 2011 only supports Internet Explorer, we have to use it, but on the bright side, whatever tricks we use to make it work do not have to be ported to any other browsers.
So the code below is an HTML web resource that you can modify and attach to any entity. It has a button that, when clicked, will generate a pre-defined report and attach it to the current entity as a note attachment. Basically the only parts that you need to modify are the report name and guid. You can find your report's guid by opening the report record and looking at the URL, and the name is the name that you gave it in CRM. My report is called "Public". Even though this code just creates an attachment, it is a simple excersise to create an email record with the report as an attachment.
Please see for more details CRM Reports as PDF