Microsoft Dynamics CRM 2011 Pre-Populated Emails (Alternative Approach)

Visit Website View Our Posts

Recently, we came across the need for a single-click email feature on the ribbon of a custom entity.  The idea was to be able to share CRM data as quickly and easily as possible.  Another interesting caveat was that the client wanted to have the email come directly from Outlook.

For those of you old enough to have used the internet before the iPad, you may recall that fancy-dancy “mailto” feature.  (Granted I’m only 29 but my Omron body age says I’m 50 Surprised smile).

Back to the point at hand though, CRM already has a few built in email features.  Our situation calls for something a little different.


What’s Installed By Default

CRM already has the feature of sending a link to the CRM entity you’re working with.



CRM also has a really nice Email Template feature.



Which can automatically mail-merge information pertaining to the entity to eliminate any of that “automated” feel.


What We Need

Our situation is somewhat unique, but really we want both features combined.  We want to open a new message like the link feature: inside outlook and with one click.  However, we need more than just the link.  We want to have a brief summary of the call report with a  link to it.

Here’s an example email of what we’d like to send:



Adding the Button

The first thing we need to do is add the button to the ribbon like so:


If you are unfamiliar with the ribbon, Microsoft offers some really nice walkthroughs.  I’d start with

For our situation, the XML that matters is our Action

<Actions> <JavaScriptFunction Library="$webresource:cei_example.js" FunctionName="emailContact" />


Adding our JavaScript

At this point, the button should be on the form.  From here, we need to add the JavaScript to open our populated email message.

To do this, add to the Form OnLoad events the following function:

emailContact = function() {
if ( != null) {
var sRptID ='{', '').replace('}', '');
var sLink =  "" + sRptID + "&etc=10011";

      var sSubject = 'Contact - ' + Xrm.Page.getAttribute("firstname").getValue() + ' ' + Xrm.Page.getAttribute("lastname").getValue();
var sCustomer = '';
if (Xrm.Page.getAttribute("parentcustomerid").getValue().length > 0){
sCustomer = Xrm.Page.getAttribute("parentcustomerid").getValue()[0].name;
var sBody = '---\n\nCustomer:\t' + sCustomer + '\n\n' + sLink + '\n\n---';

var sMailTo = 'mailto:?subject=' + escape(sSubject) +
'&body=' + escape(sBody);


   } else {
alert('You must save the contact before emailing.');



Note: If you change the name of the function, make sure it matches the name inside your Ribbon XML.


What about Window.Open

If you use Window.Open to trigger the email (or OpenStdWin), the user will get a blank IE page inside of Outlook. By using the parent.location for your mailto, you’ll have a consistent user experience across IE and Outlook.


Seeing the Final Results

Now whenever a user wants to share a call report, they can easily hit the “Email Call Report” button.  Add any of the fields you want.


For our needs I ended up with the following; however, this technique can add whatever field you’d like.



While this isn’t a tool in the toolbox I’d use daily, it can be valuable when the situation calls for it.  I hope you enjoy!

Post by: Paul Way, Customer Effective

Show Buttons
Hide Buttons