Friday, 21 July 2017

Getting Mobile Number From Share Point user Profile

// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.

var userProfileProperties;
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {

   // Make sure PeopleManager is available

   SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {

       // get the target users domain name and account name.

    var targetUser = "i:0#.f|membership|inspiredata@gbtmarketingreview.onmicrosoft.com";

    // Get the current client context.

    var clientContext = new SP.ClientContext.get_current();

    //Get PeopleManager Instance

    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get the properties to retrieve

    var profilePropertyNames = ["AccountName", "FirstName","LastName","Assistant", "Office","Personal site","WorkPhone", "Mobilephone","CellPhone","Fax","Department" ];

    var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(
    clientContext,
    targetUser,
    profilePropertyNames);

    // Get user profile properties for the target user

    userProfileProperties =peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);

    // Load the UserProfilePropertiesForUser object.

    clientContext.load(userProfilePropertiesForUser)

    //Execute the Query

    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
   });

});




// This function runs if the executeQueryAsync call succeeds.

function onRequestSuccess() {

    var messageText = "\" AccountName \" property is "
    + userProfileProperties[0];
    messageText += "<br />\" FirstName \" property is "
    + userProfileProperties[1];
    messageText += "<br />\" LastName \" property is "
    + userProfileProperties[2];
    messageText += "<br />\" Assistant \" property is "
    + userProfileProperties[3];
    messageText += "<br />\" Office \" property is "
    + userProfileProperties[4];
    messageText += "<br />\" Personal site \" property is "
    + userProfileProperties[5];
    messageText += "<br />\" HomePhone \" property is "
    + userProfileProperties[6];
    messageText += "<br />\" Mobilephone \" property is "
    + userProfileProperties[7];
    messageText += "<br />\" CellPhone \" property is "
    + userProfileProperties[8];
    messageText += "<br />\" Fax \" property is "
    + userProfileProperties[9];
    messageText += "<br />\" Department \" property is "
    + userProfileProperties[10];
 alert("WorkPhone"+userProfileProperties[6])
    $get("Display").innerHTML = messageText;
}

// This function runs if the executeQueryAsync call fails.

function onRequestFail(sender, args) {

    $get("Display").innerHTML = "Error: " + args.get_message();
}

No comments:

Post a Comment

How to get the value from web.config(if any value assign as static Key)

Web.Config File:   <appSettings>     <add key="DomainName" value="PW" />     </appSettings> Cl...