Retrieve user profile properties by using the JavaScript object model in SharePoint 2013

You can use this for all properties of the current user
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties
Use the following to get the profile information for a specific user
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName='domain\username')?
The following script will access four User Profile properties (AccountNameuserDisplayNameEmployeeID and workEmail) through the JavaScript Object Model

<script type='text/javascript'>  


    var workEmail = "";  
    var EmployeeID = "";  
    var Division = "";  
    var userDisplayName = "";  
    var AccountName = "";  

    $.ajax({  

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",  
        headers: { Accept: "application/json;odata=verbose" },  
        success: function (data) {  
            try {  
                //Get properties from user profile Json response  
                userDisplayName = data.d.DisplayName;  
                AccountName = data.d.AccountName;  
                var properties = data.d.UserProfileProperties.results;  
                for (var i = 0; i < properties.length; i++) {  

                    if (property.Key == "WorkEmail") {  
                        workEmail = property.Value;  
                    }  

                    if (property.Key == "EmployeeID") {  
                        EmployeeID = property.Value;  
                    }  
                    if (property.Key == "Division") {  
                        Division = property.Value;  
                    }  

                }  
                $('#AccountName').text(AccountName);  
                $('#userDisplayName').text(userDisplayName);  
                $('#EmployeeID').text(EmployeeID);  
                $('#workEmail').text(workEmail);  
                $('#Division').text(Division);  


            } catch (err2) {  
                //alert(JSON.stringify(err2));  
            }  
        },  
        error: function (jQxhr, errorCode, errorThrown) {  
            alert(errorThrown);  
        }  
    });  

</script>  

<h2><strong>Employee Details</strong></h2>  
<br />  
AccountName   <span id="AccountName"></span>  
DisplayName   <span id="userDisplayName"></span>  
EmployeeID    <span id="EmployeeID"></span>  
Email Address <span id="workEmail"></span>  
Division      <span id="Division"></span>

Comments

Popular posts from this blog

Download Visakhapatnam Tirupati AC Double Decker Express Act