Monday, July 30, 2007

EmailTo via JScript

One of the shortcomings that I've found with some of the out-of-the-box features in MSCRM is the Email field. It's underlined, so it is supposed to be a link but when you click on it, instead of opening an email page like a URL does for a web page, it does nothing.

I finally decided to spend some time on figuring out some way around the "copy/paste" method that I have told so many users previously to do to work around this issue. And while I did not solve the onClick problem I did at least find a way to get an email page to come up with the email from the email field filled in. A huge win over the "copy/paste" method.

I found a way through JScript in the ISV.config to get everything I needed. I knew that I could use the "mailto:" call from the HREF HTML tags but I wasn't sure on how to reference it. So, after a little research I found a pretty cool way to get around this problem. So, I cannot by any means take full credit for figuring this out, I can only claim credit for finding the pieces necessary and putting them together to get what I needed done (as I'm sure most of us do through the wonderful knowledge share called the Internet). So, thanks to anyone any everyone who has posted about this, I probably saw your posts and they have contributed to this:

<button title="Email" tooltip="Send Email" icon="/_imgs/ico/16_send.gif" javascript="window.navigate('mailto:'+crmForm.all.new_email.DataValue)" passparams="0" winparams="" winmode="0">

The key is the JavaScript attribute and the window.navigate call. Once the window.navigate reference was made it was also very great to see I could call any field value on the form to my JavaScript stored in the ISV.config. That ability alone opens up a lot of doors to new possibilities. It makes sense that all of the supported hooks that we as developers are given are JavaScript that we could use the exact same calls from a different source, it just wasn't something I had tried until now. Once I had those points down it was a piece of cake.

So, now I have a button along the toolbar that will open up your default email client to whatever email address you specify. I'm sure there are some much more complex scripts that can come from this (like a primary email selection box that then pics the corresponding email address to send the email to).

Happy coding,

David Fronk
Dynamic Methods Inc.


Morten Dybdahl said...

Txs for very useful "easy" hint. I instruct my customers to always first check information related to the contact (activities, notes, relationships etc); before sending e-mail to people you don't know that well. At the same time; always use Meeting and E-mail from Outlook; to get momentum from existing knowledge and practice. In this example people don't want the CRM e-mail button; but the Outlook e-mail. So I have added your button; and removed the standard e-mail button in the form load event for the contact screen.

Prashanth N said...

Hi David,

thats great info..

I have one requirement same as u done in this post.

But i need to pass a group of email id's to the Outlook Email form's TO field.
How do i do this ?

Dynamic Methods said...


You should just need to add a semicolon ";" and then the next email address. I haven't done it personally but that's what my thought would be. Otherwise do a little research on the "mailto" capabilities of JavaScript and see if the function is even capable of doing that. I don't think that using multiple "mailto"'s would work but again, I haven't done it. Also, you'd have to be sure that all of the emails that you wanted to send to were all on the same page.

Let me know if you find anything. Also, if you don't let me know and I'll see if I can find anything.

David Fronk
Dynamic Methods Inc.

Post a Comment