Thursday, June 19, 2014

SharePoint 2013 - Client Object Model - Document Library Author error and SP.UserProfiles.PeopleManager Error Handling

If you are getting the PeopleManager as object referance error, then try this method.

Try to load the script file above the calling function.
< script src="/_layouts/15/sp.userprofiles.js" type="text/javascript" >

Try to wrap the function inside the SP.SOD.executeFunc. This will make sure to load the profile manager.

   SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
   SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {
    var targetUser = "Domain\\" + createdBy.split('\\')[1]; //Splitting to get the userID
    var clientCtx = new SP.ClientContext.get_current();
    var peopleManager= new SP.UserProfiles.PeopleManager(clientCtx );
    var i = peopleManager.getPropertiesFor(targetUser)
    //This is not yet finished till you execute the query.
    function () {
        alert("Display Name:" + i.get_displayName());
    } , function (sender, args) {



If you are not able to get Author field in Document Library , try this field Created_x0020_By. This will give you the value as domain\\userid. I have splited here to get the exact user ID. (I'm not sure to get the display name from this. tried to fetch from user profile. bu the function was loading post as async. So opted for 2nd option using WF)

Happy Browsing!

No comments:

Post a Comment