1

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

  • Could you post the portion of the code where you are using get_current() and get_email()? – James Grizzle May 20 '15 at 12:56
  • Honestly that is the part I was needing. All the references I found were for adding the USerProfiles.js into a page. Those methods did not work on the display template it would error out everytime. I will however go back and see if I can find the code snippets I have tried and add them to the original post. Thanks for trying to help. – mgarza May 20 '15 at 13:00
0

first of all, there is an error in the doku: The SOD-key for userprofile.js is just "userprofile" (without js), you can verify that easily in the html.

However, this has something to to do with the user Profile Service. If the user is not synced or there is no user Profile Service application at all, this wont work. I would recommend calling the user Information list of the current site. you can Access it by using

var userInfoList = this.web.get_siteUserInfoList();

from there on you can handle it like any other list. You can get the requested user by ist id (eg there should be a method like get_byId). Usually if you use a People picker, this field contains both, the user id according to the user Information list and a Display Name (the internal text Format is something like id#displayname).

as soon as you have the correct item you can call

var obj = item.get_fieldValues().Email;

and thats it.

Besides: Consider building the Lync-Integration using the SharePoint-JS-Methods like it is done in the item_person.html Display-Template:

                        EnsureScriptFunc("clienttemplates.js", "RenderUserFieldWorker", function() {
                        var getUserPersona = function() {
                            var renderCtx = new ContextInfo();
                            renderCtx.Templates = {};
                            renderCtx.Templates["Fields"] = {};
                            var fieldSchemaData = { "PictureOnly":"1", "PictureSize": "Size_72px"};
                            var listSchema = {"EffectivePresenceEnabled": "1", "PresenceAlt": Srch.Res.item_People_NoPresenceAvailable};
                            var userData = {"title": uName, "email": uEmail, "picture": uPicUrl, "sip": uSip};
                            var personaControlElement = document.getElementById(userPersonaId);
                            if (!Srch.U.n(personaControlElement))
                            {
                                personaControlElement.innerHTML = RenderUserFieldWorker(renderCtx, fieldSchemaData, userData, listSchema);
                            }
                            if(typeof(ctx.EnqueueImnRequest) == "undefined") { ctx.EnqueueImnRequest = false; }
                            if (ctx.EnqueueImnRequest == false) {
                                ctx.ClientControl.add_oneTimeResultRendered(function(){ if (typeof(ProcessImn) != "undefined") { ProcessImn(); } });
                                ctx.EnqueueImnRequest = true;
                             }
                        };
                        getUserPersona();
                    });
  • So I tried both examples. Both failed, but I am sure it has to do with the fact that the list that I am trying to pull from only has a managed property from username (and that is a people and group type). This is a contact list that was already in place on the top level site. The new requirement for the list was to create a view for all departments to see only their contacts on their site. I have all that working. They asked for Lync Presence and that is where I am now. So the only field I have to pull the from is that people and group field. – mgarza May 20 '15 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.