Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks

Search

Most popular posts
in last 360 days

Categories

My Projects

Archives

Stuff


Copyright © by David Vidmar
 
Contact me!
 
LinkedIn Profile
 
 
 

The regular nvarchar attribute with URL format is useless for anything else but link with http/https and ftp/ftps schemes.

image

 

To make things worse, if you put in link with a protocol that is not recognized by CRM validation code, http protocol gets automatically appended. So forget about using skype, navision, magnet, msnim or any other URI schemes!

image

Also, did you notice how useless Email format is? You can’t click and send an email to address from you default email client!

But there is a simple JavaScript trick that can be used to convert any regular nvarchar field on a form to clickable link field!

We want to turn the link into blue and underline it. Using same CSS style as for build in URL format is not the way to go, since it includes CSS behavior that validates schemes and adds http URI scheme if none is used.

image

We can recreate the look and feel with just a few lines of code. Put it in OnLoad event and substitute attribute name.

var emailTextBox = crmForm.all.emailaddress1;

emailTextBox.style.color = "#0000ff";
emailTextBox.style.textDecoration = "underline";
emailTextBox.attachEvent("ondblclick", openEmail1);

function openEmail1() {
if (emailTextBox.DataValue != null)
document.location = "mailto:" + emailTextBox.DataValue;
}

This is end result – colored and underlined email that you can double-click it.

image

You can change first parameter of attachEvent to “onclick” if you prefer single click.

Posted on Tuesday, March 02, 2010 11:32 PM | Filed under: Developement MS Dynamics CRM |

Feedback

# re: Creating custom link fields in Microsoft Dynamics CRM 4.0 3/20/2010 12:01 PM Brett Gilbertson
Thank you so much for this. that been looking for a solution to link to OneNote URLs, and this will do the trick perfectly.

Didn't think of the Skype url example. Might throw that in too.

# re: Creating custom link fields in Microsoft Dynamics CRM 4.0 7/20/2010 10:46 PM Brian
Excellent. Works perfectly. I also added code to change the cursor to a hand when hovering over the email. Here it is:

emailTextBox.attachEvent("onmouseover", mouseover);
emailTextBox.attachEvent("onmouseout", mouseout);

function mouseover() {
emailTextBox.style.cursor = 'hand';
}
function mouseout() {
emailTextBox.style.cursor = 'auto';
}


# re: Creating custom link fields in Microsoft Dynamics CRM 4.0 7/20/2010 11:03 PM David
Brian, thanks for the tip!

Comments have been closed on this topic.