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

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.

image

 

CRM also has a really nice Email Template feature.

image

 

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

image

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:

image

 

Adding the Button

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

image

If you are unfamiliar with the ribbon, Microsoft offers some really nice walkthroughs.  I’d start with http://msdn.microsoft.com/en-us/library/gg334341.aspx.

For our situation, the XML that matters is our Action

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

 

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 (Xrm.Page.data.entity.getId() != null) {
var sRptID = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
var sLink =  "
http://paul.customereffective.com/userdefined/edit.aspx?id=" + 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);

      parent.location=sMailTo;

   } 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.

image

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

image

 

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