Creating custom link fields in Microsoft Dynamics CRM 4.0

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


Avtor: Anonymous, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.