I am using a CSWP to build a contact list that utilizes user presence. The CSWP would query a Contacts content type and pull back the following fields: 'Title', 'Contact Name' (People Picker), 'Phone', and 'Department'. The query works fine and the contacts come back as expected.
The issue arises when trying to implement user presence. To do so I need to populate the user's email into the 'sip' property. I am having the hardest time finding a solution that can iterate through the list and place the email variable into the 'sip' property. All of the documentation that I run into is calling the get_current() and get_email() methods which cause the CSWP to error out. The error provides no detail as to why just a cookie cutter 'Go check your stuff'. Thanks for any help anyone can provide.
The problem I am having is trying to retrieve the sip address from the 'people' field.
Here is a copy of the Lync Presence code I am using.
<span> <span class="ms-imnSpan"> <a href="#" onclick="IMNImageOnClick(event); return false;" class="ms-imnlink ms-spimn-presenceLink" tabindex="-1"> <span class="ms-spimn-presenceWrapper ms-imngImg ms-spimn-imgSize-10x10"> <img name="imnmark" title="" ShowOfflinePawn="1" class="ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="" id="imn__#= line2Id =#_,type=sip" /> </span> </a> </span> <span> <a href="#" onclick="IMNImageOncLick(event); return false;" class="ms-imnlink" tabindex="-1"> <img name="imnmark" title="" ShowOfflinePawn="1" class="ms-hide" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="" id="imn__#= line2Id =#_,type=sip" /> _#= line2 =#_ </a> </span> </span> The lines that have the _#= ... =#_ are used to call JavaScript variables in CSWPs. These variables are pulled in via managed properties. I need a way to populate the sip="" with the user's email address. Currently my variable only pulls in the display name for the user.
Edit:
Try 1 - I didn't expect this to work on a CSWP display template but I did try to be thorough.
<SharePoint:ScriptLink ID="ScriptLink1" name="SP.js" runat="server" ondemand="false" localizable="false" loadafterui="true" /> <SharePoint:ScriptLink ID="ScriptLink2" name="SP.UserProfiles.js" runat="server" ondemand="false" localizable="false" loadafterui="true" /> Try 2 - Tried this. No luck
var personProperties; // Ensure that the SP.UserProfiles.js file is loaded before the custom code runs. SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js'); function getUserProperties() { // Replace the placeholder value with the target user's credentials. var targetUser = "domainName\\userName"; // Get the current client context and PeopleManager instance. var clientContext = new SP.ClientContext.get_current(); var peopleManager = new SP.UserProfiles.PeopleManager(clientContext); // Get user properties for the target user. // To get the PersonProperties object for the current user, use the // getMyProperties method. personProperties = peopleManager.getPropertiesFor(targetUser); // Load the PersonProperties object and send the request. clientContext.load(personProperties); clientContext.executeQueryAsync(onRequestSuccess, onRequestFail); } // This function runs if the executeQueryAsync call succeeds. function onRequestSuccess() { // Get a property directly from the PersonProperties object. var messageText = " \"DisplayName\" property is " + personProperties.get_displayName(); // Get a property from the UserProfileProperties property. messageText += "<br />\"Department\" property is " + personProperties.get_userProfileProperties()['Department']; $get("results").innerHTML = messageText; } // This function runs if the executeQueryAsync call fails. function onRequestFail(sender, args) { $get("results").innerHTML = "Error: " + args.get_message(); } All above examples are referenced from this page: MSDN -How to: Retrieve user profile properties by using the JavaScript object model in SharePoint 2013