Integrating Lync Status into an ASP.Net Gridview

This post describes integrating Lync status into an ASP.Net Gridview.  I had a bit of a nightmare trying to achieve this so that it worked on IE8 all the way up to IE11 .  First I had it working on IE8 but for IE9+ the status always showed as offline.  I finally made it work using the example below (using Lync 2010):

First create the Gridview – in this example we’re binding ‘analysts’ :

You’ll notice that the ID of the label is called lyncStatus, which will obviously generate a unique ID (for example ‘analystGV_ctl01_lyncStatus’, ‘analystGV_ctl02_lyncStatus’ etc) for each label when the Gridview renders.  We also use a data-id attribute to store the email address of the analyst.  I’ve seen examples in the internet where people have used the SIP URI as the ID on fields, but this won’t work in a Gridview if we’re expecting multiple instances of the same SIP (the same user, for example) and as the ID would suggest, it would not be unique!

The Text of the label displays the analyst’s name.

Now paste the following into the <head> section:

Above we include the JQuery library and specify some styles for the status of each user.

Here are the icons I use:

 

Finally, just before the </body> tag, paste this:

When the document has loaded, this piece of JQuery iterates through all elements with an ID ending with ‘lyncStatus’.  it retrieves the id and the data-id attributes (the id so it knows what element to set the Lync status on, and the data-id which stores the SIP URI (email address in my case)).  If an instance of the nameCtrl object was successfully created, and presence is enabled, it attempts to get the status for that SIP.

**Note**

I experienced intermittent issues where duplicate users would not always be rendered correctly.  That is, when GetStatus was called for a duplicate user (let’s say the same user joe.bloggs@alkanesolutions.co.uk appears twice) it would not return the correct value and OnStatusChange would never be called.  To circumvent this issue, when the first instance of each user is ‘rendered’, I then use JQuery to find all other users with the same SIP URI and to give them the same status css class.  Not ideal, but it works!

**Another Note**

If you’re testing this on an x64 platform, you must launch the x86 version of Internet Explorer.  Otherwise it appears we cannot instantiate the Name.NameCtrl object, and we will get the ‘Automation server can’t create object’ error in our ‘catch’ block.

Also if you have Lync 2013 (and not 2010 like me) you may be able to get the integration working in Chrome/Firefox too by following instructions on how to instantiate the object here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.