0

I found some code that outputs from user profiles and works but it only outputs Manager. How can this be changed to output Title, Email and Phone number?

  var managerName;
  $().SPServices({
    operation: "GetUserProfileByName",
    async: false,
    AccountName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("PropertyData > Name:contains('Manager')").each(function() {
        managerName = $(this).parent().find("Values").text();
        alert(managerName );
      });
    }
  });

I've tried changing the code section below but this doesnt work at all.

completefunc: function(xData, Status) {
    $(xData.responseXML).SPFilterNode("z:row").each(function() {
    var oTitle = ($(this).attr("Title"));

Any ideas?

1 Answer 1

0

Try below

var user = {};
$().SPServices({
    operation: "GetUserProfileByName",
    async: false,
    AccountName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("PropertyData").each(function() {
        user[$(this).find("Name").text()] = $(this).find("Value").text();
        //user.AccountName
        //user.PreferredName
        //user.WorkEmail
        //user.WorkPhone
      });
    }
});
5
  • Hi Tried Alert(user.WorkPhone) and recieved numerous alerts mostly with undefined then I got some real data. Seems to be in a loop ! Jan 7, 2015 at 16:06
  • Yes. You should place the alerts after the each loop. Once the loop completes, it will have data for the comments I placed inside the loop. Jan 7, 2015 at 16:08
  • use try and catch to stop Alert, because some profiles not have workphone... or try show me your code for verify if is correct...
    – b1c10
    Jan 7, 2015 at 16:09
  • I have it working now, Could you explain a bit more (with code) the try and catch pls? Jan 7, 2015 at 16:11
  • You don't need to use try catch.. instead you can check whether its null or undefined using if condition ... if(user.WorkPhone != undefined).. then use it Jan 7, 2015 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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