Monday, April 4, 2016

Link to a User's Delve Profile From On-Premise Search

Hybrid, hybrid everywhere, so let's all have a cloud.

That might be the worst limerick I created today, but it reflects more of what we see clients doing with their SharePoint environments; keeping a SharePoint web app or two on-premise while migrating the rest of the environment to the cloud.

A client moved their MySites to Office 365 while the rest of the intranet is on-premise. An issue was when you search for a user on the intranet, clicking the name of the user took you to their OneDrive not their Delve profile. This is residual from the on-premise to the O365 migration as the URL pointed to the old on-premise MySite URL.

OneDrive pages are really unflattering and really only show you content someone has shared with you or your private docs. Delve pages on the other hand are much prettier.

Hot

DELVE

Not

OneDrive

Back to the problem at hand. Back in the day you used to be able to link directly to someone’s MySite; the URL was easy to understand and all was good. Now if you try to link directly to someone's Delve site, there's this crazy GUID in the URL. It looks something like this:

https://tenant-my.sharepoint.com/_layouts/15/me.aspx?u=e01dbd9f-c517-4df0-b268-941858f5ed7b&v=profile

What's the GUID? Is it a SID? That doesn’t make sense. Is it the site collection ID? Maybe? I can't seem to find anything that documents what it is.

Even though that OneDrive page is fugly, at least that URL is easy to understand:

https://tenant-my.sharepoint.com/personal/user_domain_com/_layouts/15/onedrive.aspx#view=4

If you don't know the GUID for a user's Delve profile, how do you link from an on-premise people search result to their Delve profile page? Thankfully you can build a URL that uses the user's email and O365 will automagically take you to the user's Delve profile

To achieve this, I made two quick updates to the display templates.

In your search site collection, modify the display template Item_Person.html. Add these two variables around line 53:

var SPOPath = "https://tenant-my.sharepoint.com/person.aspx?user="

var DelvePath = SPOPath + uEmail;

Then update the anchor tag in < div ID="NameValue"> so that the HREF uses the DelvePath variable. Follow the same steps on Item_Person_CompactHorizontal.html too.

Publish the display template. Once these updates are made, do the same to Item_Person_HoverPanel. The only difference is this display template doesn’t get the user’s email. To get the email, add the line below to the display template before you set the DelvePath variable.

var uEmail = ctx.CurrentItem.WorkEmail;

Fix Broken User Images in Search Results

Chances are that the user’s profile picture is also broken in your on-premise results. Since we’re in these display templates, let’s hit two birds with one stone.

Open Item_Person_CompactHorizontal.html. Add this around line 121:

var DelvePic = "https://tenant-my.sharepoint.com/_vti_bin/DelveApi.ashx/people/profileimage?userId=" + uEmail +"&size=L";

Then update the userData var, around line 388, to use the variable DelvePic.

var userData = {"title": uName, "email": uEmail, "picture": DelvePic, "sip": uSip};

Repeat the steps in this section for Item_Person.html. Just note that the line numbers are very different, but the structure should look familiar.