User Profile Services via Client Object Model

I was recently thinking through ways to help drive adoption of an intranet and engage users to explore the various capabilities of the system. One thought was to alert users if they have not supplied a profile photo, or a short bio in their MySite. Sure we could do this with web services, but I thought I’d figure out how to do it with the client object model with ECMAScript. After a lot of searching, I kept finding blog posts that said I was out of luck and there was no way to query User Profiles via the client object model. At a high level, that assessment is correct, but what we can do is query the user info list of the current site.

When I first started this, none of the test users in my lab had a profile picture, so I added one and found that my script kept returning a null object instead of my picture. The hidden Easter egg here is that the site’s user info list isn’t updated in real time. If you head over to Central Administration -> Monitoring -> Review job definitions and dig down the list you’ll find a job called “User Profile Service Application – User Profile to SharePoint Full Synchronization“. This timer job will execute every hour and synchronize the properties of your User Profile Services to the site user info list, so the picture that was set on the MySite is now accessible via the user info list.

First things first, we need to find out the ID of the user that’s currently viewing the page (this is the physical numerical record of the user in the site’s user info list, not the login username). Credit to Mike Oryszak (@next_connect) and his blog post on using the status bar to display active workflows for getting me in the right direction on this piece. We’ll start out by grabbing the current web context and fire off that query. If the query is successful in executing, it’ll call the onUserSuccessMethod function.

var context = null;
var web = null;
var curUser = null;

function getUser() {
	context = new SP.ClientContext.get_current();
	web = context.get_web();
	curUser = web.get_currentUser();
	curUser.retrieve();
	context.load(web);
	context.executeQueryAsync(Function.createDelegate(this, this.onUserSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}

Now that we have our context we’ll create a variable called user and assign it to the current user object, and call our loadProfile function to do the profile query.

function onUserSuccessMethod(sender, args) {
	var user = web.get_currentUser();
	loadProfile();
}

The loadProfile function defines the user info list, builds the CAML query to get the record for the current user, and fires that query off. If the query is successful in executing, it’ll call the onProfileSuccessMethod function.

function loadProfile() {
	context = SP.ClientContext.get_current();
	web = context.get_web();
	userInfoList = web.get_siteUserInfoList();
	camlQuery = new SP.CamlQuery();
	camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>' + curUser.get_id() + '</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>');
	this.listItems = userInfoList.getItems(camlQuery);
	context.load(listItems);
	context.executeQueryAsync(Function.createDelegate(this, this.onProfileSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}

Now that we have the result set from our query (in the form of a listItems object), all we need to do is grab the first (and only item), this will be on index 0 in the array, and analyze the picture field to see if there’s a value there or not. If there is a picture object, we’ll grab the Url to it and save it in a new variable (pictureURL) just in case we want it. If there is no picture object, we’ll fire off a call to SP.UI.Status to add a new status bar telling the user they don’t have a photo, with a link to their profile where they can add one.

function onProfileSuccessMethod(sender, args) {
	var item = listItems.itemAt(0);
	var picture = item.get_item('Picture');
	if (picture) {
		var pictureURL = picture.get_url();
	} else {
		noPicture = SP.UI.Status.addStatus('Profile Photo', 'You have not added a profile photo to your account. <a href=\'http://mysites/person.aspx\'>Add one now!</a>');
		SP.UI.Status.setStatusPriColor(noPicture, 'blue');
	}
}

You’ll notice that both getUser() and loadProfile() have references to an onFailureMethod function, in the event that our query fails. This will be a simple function to just alert our error.

function onFailureMethod(sender, args) {
	alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
}

Now that we’ve got all of our functions written, all we need is a simple call to our getUser() function (after the core SharePoint JavaScript has loaded, of course).

ExecuteOrDelayUntilScriptLoaded(getUser, "sp.js");

Putting it all together:

My “Michael Greene” account has a user profile image, so we just see normal SharePoint with no profile photo alerts.

My “Setup Account” account does not have a profile image, so SharePoint prompts us that we should add a photo.

Due to the fact that we have to wait on the timer job to run and update the user info list with the new photo, it’s possible that the user could add a photo then still see the prompt telling them they haven’t. In a true application of this, we could add a condition to check the Modified time of the user info list record to see if the record has been “updated” in the last hour, to avoid that false positive. Only if the record has been updated within the hour and has no photo, should we alert the user.

Delivering SharePoint Success

Triangle SharePoint User Group
Here's a few photos I captured today of @ getting the crowd excited about SharePoint Project Mgmt. @ http://t.co/nhgRGuW #in
@webdes03
Michael Greene

We just finished wrapping up a great event with the Triangle SharePoint User Group focused on the project management side of SharePoint adoption and deployment. Special thanks to Dux Raymond Sy (@meetdux) for coming down to Raleigh for this special event. The Triangle SharePoint User Group meets on the first Tuesday of every month, and additional details about meeting topics and group information can be found on our website, or via our LinkedIn group.

Dreaded Collaboration

There’s an interesting article titled “Why Some People ‘Dread’ Collaboration” in the September 6th issue of Information Weekly. The author discusses the link between the slow adoption of collaboration technology and the inherent flaws in strategy and governance. The article cites a survey in which over 500 executives were polled on their collaboration strategy. 80% of those executives felt that enterprise-wide collaboration was key to the companies success, and 75% of them planned to increase use of collaboration and communications tools in the coming year. On the flip side, a similar survey showed that the actual adoption of collaboration platforms tends to lag behind the initial deployment by five to eight quarters-pretty staggering given the current emphasis and investment in collaboration technology. Do we really want to have to wait that long to realize the investments of our shiny new collaboration platform?

So what’s the reason behind this lag? Enter the mystical uncontrollable beast of governance and strategy. The author runs through a particular example in which the corporate direction to utilize collaboration tools is so downright impractical that the end users develop a sort of hatred for the technology; the “put everything you do  in a wiki” strategy.

If people use wikis-or any other collaboration tool-just because they’re compelled to do so, they’ll get lost in the white noise of misplaced communications. If users back away, it’s not necessarily because they’re hidebound or anti-social, or because the technology is inherently flawed (wikis are terrific for many things), but because they’re not realizing the value.

Information Week, 9/6/2010, “Why Some People ‘Dread’ Collaboration”

Read more →

19
Sep 2010
CATEGORY

Technology

COMMENTS 1 Comment

Facebook Chat via 3rd Party Application

Having grown up with instant messaging as an integral part of communication (yes, I’m of that generation that would rather IM, Text or E-Mail than actually use a phone to make a call) I’ve obviously noticed that pretty much nobody uses AIM and those other chat protocols that we all grew up with. Just for kicks I logged into my AIM account to find maybe 3 people on my buddy list actually online. While protocols like Skype have made a dent in the market, having cracked the voice and video chat world, the big player now is actually none other than our illustrious Facebook. Continuing that trend of rooting itself in absolutely everything anyone does, pretty much everyone has a Facebook account, making it the ideal medium to keep in touch.

Read more →

22
Aug 2010
CATEGORY

Technology

COMMENTS No Comments

SharePoint Killed the Intranet Star?

There was an interesting Tweet earlier from Richard Harbridge regarding the effect of SharePoint on intranet design. The article pointed out several interesting points regarding the complexity of developing on an intranet optimized platform. But while the platform itself has certainly been optimized to support the scope and scale of intranets (both large and small) the platform itself really needs to be tailored to meet the specific needs of the business.

Does SharePoint Destroy Intranet Design? http://bit.ly/95tKhB
@rharbridge
Richard Harbridge

Read more →

07
Jun 2010
CATEGORY

Technology

COMMENTS 9 Comments

SharePoint Saturday DC

There’s tons of posts flying around the blogosphere about SPSDC. Like most, I have to tip my hat to Dux (@meetdux), Jennifer (@jensterd), and the gang who put themselves through (what I’d imagine was) a logistical nightmare coordinating an event with over 90 speakers and what would turn out to be close to 1,000 attendees. From an attendee point of view everything went up without a hitch thanks to their great planning. For me this event was just as much about meeting my long lost Twitter friends in person as it was about the content. Ever since I joined the SharePoint community I’ve been amazed at how incredibly open, supportive and friendly the community is; though I imagine we’d all be out of a job if we failed at collaborating.

I attended some great sessions by Mark Anderson (@sympmarc), Christina Wheeler (@cwheeler76), Fabian Williams (@fabianwilliams) and Mike Oryszak (@next_connect), was finally able to put real life faces to the folks behind those avatars that oh-so-often show up in my Twitter feed, and meet loads of new people that now seem to be popping up in that same feed. This being my first SharePoint Saturday, I’m still taking it in to a certain extent. These events are a great place to share technical knowledge, learn practical skills to take back to your day-to-day work, and network with new people in this exciting field (that might have sounded a lot like a canned marketing line, but it’s true).

It may have been the sheer scope and record attendance of SPSDC that lead to such a mixed bag of sessions, but there was truly something for everyone. Some of the sessions were very technical, while others were more process oriented, and as with the sessions, I found the attendees to be quite a mix too. I spoke to people that were IT Pros and top shelf consultants, and I spoke to people that were brand new to SharePoint and didn’t really know much of anything. The only problem I had was picking which sessions to attend since there were so many going on at once. This clearly could have been a two-day event, though that would have defeated the “SharePoint Saturday” name wouldn’t it.

The last point I’ll make is the importance of Twitter. All of these people use Twitter (after all, we are in the business of collaboration) and it was Twitter that ultimately brought me to SPSDC. Twitter even brought me to people after I got to SPSDC; at one point I was browsing the #SPSDC hash tag and discovered that Janis Hall (@janishall) was in the same room, sitting behind me. If you’re a SharePoint person, you really can’t afford to not follow the people linked in this post! All in all, a great weekend with even greater people; now I just have to decide which event to attend next, though I’m starting to lean towards SPS Chicago at the end of July; we’ll have to see how the schedule pans out.

18
May 2010
CATEGORY

Technology

COMMENTS 2 Comments

Embracing SharePoint in the Workplace

There was an interesting discussion going on over at SharePoint Overflow about the use of SharePoint as an intranet/extranet portal that I thought I’d talk about just a little bit more. The question that came up was more on the capabilities of SharePoint and how they relate to the functional requirements that the original poster mentioned, but there’s a lot to be said in the fine lines of the post. In this particular scenario, the poster was looking for an answer as to if SharePoint was the solution they needed as a platform for their business (an unnamed fortune 500 company), but ultimately it spawns a whole new set of questions. How do we fully embrace SharePoint in the workplace, how do we communicate the effectiveness of the SharePoint platform, and how do we reap the benefits of the increased synergy and platform consolidation that SharePoint is a catalyst of.

At the end of the day, your business (large or small) needs a strategy on collaboration. Whether you’re collaborating internally or externally, whether you’re interacting with documents or reporting metrics, you need a platform that meets a few criteria no matter how big or small your business is.

Read more →

29
Mar 2010
CATEGORY

Technology

COMMENTS No Comments

Enhance Document Libraries with Custom Document Type Icons

With SharePoint being such a fluid platform it’s easy to extend the capabilities of something like a simple document library to really integrate with your everyday business process. That said, in a media production or design environment many of the file types used just show up as the default “paper” icon. In this article I’ll walk through the process of adding additional document type icons to SharePoint.

This solution requires access to the physical server and permissions to reboot IIS.

To get started, we need to determine what file types we want to add icons for and as applicable, if there are any default icons definitions that we want to change. As an example, SharePoint uses a generic icon for .png files, but I’d really like the Fireworks icon to be used, so we’ll need to change the default definition for that type. Once we’ve determined what icons we need, we need to gather those icons and make 16px square GIF files for each one. SharePoint’s naming lexicon uses icXXX.gif where XXX is the extension of the file type the graphic represents (ie: icbmp.gif for a BMP, icdocx.gif for DOCX).

Once you’ve got your icons put together it’s time to move them to the server and make the necessary changes to the server.

Read more →

07
Feb 2010
CATEGORY

Technology

COMMENTS No Comments