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)

Create PDF and send email

(0) ShareShare
ReportReport
Posted on by 483

Hello,

When the case is Approved i want to create PDF and send email as an attachment with Case details in PDF . Please suggest what would be best approach ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at
    RE: Create PDF and send email

    Refer this:

    community.dynamics.com/.../crm-workflow-email-crm-report-as-pdf-attachment

    Hope this helps

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Create PDF and send email

    Hi Krishna,

    This is not so simple, but the logic would be as follows.

    First you need to create an SSRS report, that will take a Case Id parameter (better you prefiltering in this case).

    The I would use JS code to do the following:

    1. Create an Email Activity using Web Api (or call action), and get the Email Id back from the process.

    2. Get the Reporting Session by calling the following function (attached function based on account):

    var reportingSession = getReportingSession(accountId);

    function getReportingSession(accountId) {

       var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='account'><all-attributes /><filter type='and'><condition attribute='accountid' operator='eq' value='" + accountId + "' /> </filter></entity></fetch>";

       var reportName = "AccountReport.rdl";

       var reportGuid = "DC06A823-C265-D311-6144-1252A24B35B1";

       var path = context.getClientUrl() + "/CRMReports/rsviewer/QuirksReportViewer.aspx";

       var req = new XMLHttpRequest();

       req.open("POST", pth, false);

       req.setRequestHeader("Accept", "*/*");

       req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

       req.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:CRM_FilteredAccount=" + strParameterXML);

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

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

       var rc = new Array();

       rc[0] = req.responseText.substr(x + 14, 24);

       rc[1] = req.responseText.substr(x + 10, 32);

       return rc;

    };

    3. Create the attachment object, and call the function to create the attachment:

    var attachment = Object();

    attachment["subject"] = "File Attachment";

    attachment["filename"] = "MyFile.pdf";

    attachment["mimetype"] = "application/pdf";

    attachment["objectid_email@odata.bind"] = "/emails(" + activityId + ")";

    attachment["objecttypecode"] = "email";

    attachment["body"] = binaryPDFContent;

    createEmailAttachment(attachment)

    function createEmailAttachment(attachment) {

       return $.ajax({

           method: "POST",

           contentType: "application/json; charset=utf-8",

           url:  clientUrl + "/api/data/v8.2/activitymimeattachments",

           data: JSON.stringify(attachment),

           dataType: "json",

           beforeSend: function (xhr) {

               xhr.setRequestHeader("Accept", "application/json");

               xhr.setRequestHeader("OData-Version", "4.0");

               xhr.setRequestHeader("OData-MaxVersion", "4.0");

           }

       });

    };

    The code and logic might have to be tweaked a little for your needs, but hopefully this will help you enough to get you started.

    Hope this helps.

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at
    RE: Create PDF and send email

    Also refer this:

    crmpankaj.blogspot.in/.../send-pdf-file-as-attachment-in-mail.html

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Create PDF and send email

    One more thing.

    I have not checked this to see if it will work in your case, but Andrew Butenko recently published a tool that allows you to Send an Invoice in PDF format using his Workflow Tools. You should check it out. AFAIK it comes with the Source code.

    butenko.pro/.../uwt-email-invoice-in-pdf-format

    Thanks Andrew.

    Hope this helps.

  • dkrishna Profile Picture
    483 on at
    RE: Create PDF and send email

    Thaanks Eric.. i want to upload PDF in SharepointDocumentlocation is it possible after creating and before sending ?

  • dkrishna Profile Picture
    483 on at
    RE: Create PDF and send email

    Thanks Aric.. i want to upload PDF in SharepointDocumentlocation is it possible after creating and before sending ?

  • Shidin Haridas Profile Picture
    3,497 on at
    RE: Create PDF and send email

    Krishna Prasad,

    In addition to the other answers, I just want to mention that such requirements, which involve quite a bit of custom coding / accelerators can be easily achieved through CRM Online, with the power of MS Flow!

    But i understand that not every business wants to have CRM Online.

  • dkrishna Profile Picture
    483 on at
    RE: Create PDF and send email

    Can you pls give some example how to implement it ?

  • dkrishna Profile Picture
    483 on at
    RE: Create PDF and send email

    In My Scenario Once Case is approved and One record is created in ApprovedCase after that only i need to Create PDF based on some pdf format and send email . I want save in sharepointdocumentlocation and relate to Case so that next time we can view this pdf at any time . Pls suggest for this which is best approach ?

  • Suggested answer
    Shidin Haridas Profile Picture
    3,497 on at
    RE: Create PDF and send email

    If you are on an Online Subscription plan, you can do the following:

    In CRM:

    1. Create a Word Template for the Case record.

    2. Have a workflow which does the following: On Case Status change to Approved, use OOB Action to 'SetWordTemplate' and choose the newly created

    Word Template.

     

    CheckPoint 1: On Case Approval, you should see the Word Document attached to the 'Notes' section of the Case Record.

    In MS-Flow:
    Trigger:
    On create of Note attachment.

    Condition: Check if 'IsDocument=true' & FileName = '{TheTemplateName}'

    Actions:

    1. Upload the attachment to OneDrive. (Do use convertToBase64())

    2. Convert the attachment to PDF in OneDrive. (This is the main step)

    3. Create a new email in Dynamics365.

    4. Create an attachment (from step 2) in Dynamics365. Set regardingObject to the email created in Step 3.

    You should now see the email in CRM with the PDF version attached.

    Using Flow connectors, you can connect to your SharePoint instance and upload it to the required folder/path.

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