One of our clients hired Rightpoint to build an intranet with lots of social features. On each team site, the client wanted a widget that pulled four team members and displayed them as shown in the screenshot at the bottom. Pretty easy for any seasoned developer. However the client added one additional stipulation: every time the page loads, different people had to show up randomly. Still not a bad deal for a seasoned developer. Here’s how I handled the development.
The main part of the code is the REST API call. I'll break down all of the parameters.
Here is the breakdown of the code that creates the URL.
Get the protocol and host from the location object.
Note that you can also use the spPageContextInfo object. It would look like this:
Set the row limit to 4. This will limit the results to just 4.
Select a random number between 1 and 1001. This randomizes the results.
Set the URL for the ajax call.
The service link variable is made up of 4 parameters:
queryText - provides the name of the team. the value turns out to be PrimaryTeam='Battle Creek'
sourceId – tells SharePoint to pull the data from the people in SharePoint. The sourceid is a guid and is the same value in any SharePoint farm.
sortList – tells SharePoint to sort the results randomly.
rowlimit - Limits the number of results returned.
The next piece of code is the actual call to the REST service.
The CSS took a bit to figure out, but once I did, it became easy. Basically I used nested divs. One for the outer container and then 4 more for each person. The CSS is below