Function

$().SPServices

Web Service

UserProfileService

Operation

GetUserProfileByName

Example

Here is an example of using GetUserProfileByName from nileshc, adapted slightly.


function get_user_profile_by_login(login) {
  var user = {};
  var params = {
    operation: 'GetUserProfileByName',
    async: false,
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("PropertyData").each(function() {
        user[$(this).find("Name").text()] = $(this).find("Value").text();
      }); // end each
      // Easy names
      user.login = user.AccountName;
      user.full_name = user.PreferredName;
      user.email = user.WorkEmail;
    } // end completefunc
  };
  if (login != null) {
    params.accountName = login;
  } else {
    params.accountName = $().SPServices.SPGetCurrentUser({
      fieldName: "Name"
    });
  }
  
  $().SPServices(params);
  return user;
}

This example gets the Manager value for a specific user account:

$().SPServices({
  operation: "GetUserProfileByName",
  async: false,
  AccountName: "MBULOGIN\\will266",
  completefunc: function (xData, Status) {
    firstName = getUPValue(xData.responseXML, "FirstName");
    office = getUPValue(xData.responseXML, "Office");
   }
});

function getUPValue(x, p) {
  var thisValue = $(x).SPFilterNode("PropertyData").filter(function() {
    return $(this).find("Name").text() == p;
  }).find("Values").text();
  return thisValue;
}

Last edited Jun 28, 2013 at 4:21 PM by sympmarc, version 6

Comments

No comments yet.