Dynamics CRM Workflow - Automatically Email any Report generated in CRM as a PDF attachment

Time for another Dynamics CRM goodie...

Send an invoice to a customer with a pdf attached using a dynamics crm workflow

We try to automate as many things as we can, automatically sending invoices is one of them. Workflow as you know in Dynamics CRM is very powerful, specially the ability to create custom activities and hook into the pipeline. We took advantage of this, we created a custom workflow activity that takes in any entity, Email and a Report, automatically turn it into a PDF, attach it to the email and send the email.

Take a look at this 5 minute video to see how it works. If you're interested in using this in your organization contact me via this link.

Under The Hood


Report2Pdf
This class does the heavy lifting, it has a method called Download, connects to the report server, configures the parameters and renders the report as a PDF then returns a byte array.

public
class Report2Pdf
{
    public static byte[] Download(string rsUrl, string rseUrl, 
        System.Net.NetworkCredential credentials, string report, 
        Report2PdfParameter[] inputParameters, string culture)
    {


Workflow Activity
Straight forward, read the configuration data, makes a call to the Report2Pdf.Download method, creates an activitymimeattachment then executes a SendEmailRequest.

byte[] data = Report2Pdf.Download(config.Url, config.ExecutionUrl,
    new NetworkCredential(config.UserName, config.Password, config.Domain),
    report.Location, rps.ToArray(), config.Culture);


LINQ and Dynamics CRM
Thanks to Amanda and the team at XrmLinq for giving us access to their library. This has made data access so much easier. Something that would take atleast 10-20 lines of code and a lot of effort messing around with FetchXml has now been reduced to 3 lines and LINQ!

var
config = (from c in xrm.ReportServerConfigurations
              where c.ReportServerConfigurationId == report.ConfigurationId
              select c).SingleOrDefault();

5 Comments

  • Your link to the video is no longer active apparently. It would be helpful to see video and see this in action. I am looking to automatically send out quotes and sales orders from CRM once they are generated. We currently have to do that manually exporting the reports. I can be reached at "mgierach at fabricimages dot com"

  • Sorry Marc, link updated

  • Hi there

    I've been looking for a PDF-solution and found this. I've also been looking on some add-ons to CRM but I would like to hear from you about this solution. I'm writing here because the contact-link is broken.

    Can i have an email adress or something? Thanks

  • Hi Rasmus, try this link instead http://www.magnetism.co.nz/Utility/contact_us.aspx

  • Video is not working. I'd be interested to see this working.

Comments have been disabled for this content.