Friday, September 5, 2008

Adding Presence to CRM Form fields

As you all know “Presence” is now part of CRM 4.0. To enable presence the client machine only
needs communicator installed.

In CRM 4.0 the presence control is only enabled for contact and system user entities on some
views and inside lookups. You can read more about it here.

What I was really after is integrating presence for other CRM Form fields of type email or phone.
This was actually very simple since all you need to do is create an instance of “
Name.NameCtrl“ control and show or hide it using two simple methods.

The majority of the code takes care of the positioning of the Presence on the crmForm on the right edge of each CRM field (like a lookup).

When you add presence to a field also send the tab index where the field resides for positioning purposes because crmForm scrolling is tab related.

The Presence DLL is installed with office. So if you’re having trouble seeing it,
usually running a repair on office solves the problem.

Add the code to the entity onload event

var ocs = new ActiveXObject("Name.NameCtrl");

function OnCrmPageLoad()
AddPresence( "emailaddress1" , 0 );
AddPresence( "telephone1" , 0 );

function AddPresence( elementId , tabIndex )
if( typeof(ocs) == "object" )
var element = document.getElementById( elementId ); = tabIndex;
element.attachEvent( "onmouseover" , ShowOOUI );
element.attachEvent( "onmouseout" , HideOOUI );
window. attachEvent( "onscroll" , HideOOUI );

// show Messenger icons
function ShowOOUI()
var element = event.srcElement;
var elemVal = element.DataValue;
if( !(element && elemVal) )

var offsetX = -20;
var offsetY = -2;

for (var parent = element; parent; parent = parent.offsetParent)
if (parent.offsetLeft)
offsetX += parent.offsetLeft;

if (parent.offsetTop)
offsetY += parent.offsetTop;

var scrollTop = document.getElementById("tab" +;
ocs.ShowOOUI(elemVal, 0, offsetX + element.offsetWidth, offsetY - scrollTop);

function HideOOUI()



Mike Shaw said...

I think this is 'almost' an ousanding piece of integration... however it falls over on one fundamental point of functionality which renders it useles for emailing. When mailing a contact from the grid the track in CRM options exist and I can choose whether I want to record he mail back in to the CRM database. When I select it from the attribute it opens a clean Outlook mail form but with no CRM options. Do you know if this can be built in. At this moment I have to use the akward work around of retrospectively tracking back in to CRM.


Adi Katz said...

Hi Mike,

If outlook is opened (CRM add-in is loaded) then you are able to see the CRM ribbon and track your email.
You might try using automation e.g. new ActiveXObject(“outlook.application”) in order to load crm functionality.

Anonymous said...

Hello Adi,

Is it possible to always show the presence icon (if there is data in the field of course). In order words not on mouseover en mouseout?