SharePoint and displaying OCS Presence using JavaScript

I found a really neat way of displaying presence information using JavaScript. Of course, I got help from various tutorials, but I have decided to share some of my findings as well 🙂

The Init.JS javascript file contains the methods you need to use to get and display OCS presence information.

To simply check if a user has an OCS presence of online or offline via javascript, you can create an instance of Name.NameCtrl.1 active x object and call the get status method. This method will return you a number that determines the different presence statues (i.e. online, busy, away, do not disturb, offline).

<javascript type=’text/javascript’>

var IMNControlObj=new ActiveXObject(“Name.NameCtrl.1”);

var state = (IMNControlObj.GetStatus(‘phil.lau@phillau.com’,1));

if(state ==1)
{
 document.write(‘Offline’);

}
else
{
 document.write(‘Online’);
}

</script>

The following example will show the presence icon plus the dropdown menu that is available in the OCS client  followed by Phil Lau.

<span><img border=”0″ valign=”middle” height=”12″ width=”12″ src=”/_layouts/images/imnhdr.gif” onload=”IMNRC(‘phil.lau@philau.com’)” id=’sampleId1′ ShowOfflinePawn=1/>Phil Lau</span>

You can place a content editor web part onto a sharepoint web part zone and test out the JavaScript functions available for displaying the presence information of a user.

A prequisite for this to work is to have Office Communicator client  installed on your machine and of course, SharePoint 🙂

Advertisements

3 Responses to SharePoint and displaying OCS Presence using JavaScript

  1. psined1 says:

    this worked for us, but stopped after we upgraded to MS Office 2010. Despite that contact is resolved (shows organizational info etc), the GetStatus always returns 1 (offline) and Office Communicator chat can not be started.

  2. Gosia says:

    Hi,

    do you know how send OCS message directly from SharePoint 2010. I want to add functionality “Send Instant Message” to my web part (it needs to be client side solution),

    Best regards,
    Gosia

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: