0

I am looking to grab user information to auto populate fields in a custom form. InfoPath is out of the question so it needs to be done through JavaScript. This article is close to what I need but I need some assistance in getting it correct. The fields I need to tap into are the username, phone extension and division. These are all fields in the under the user profile information. I have copied the code here. I don't understand it completely so I am looking for guidance to capture, display and save the data within the form.

function GetPeople(){
var acctName; // stores the login
var assigned; // value from people picker field
var workPhoneExt; // stores assigned's work phone
var personDivision; // stores the login

// Get people picker value
assigned = $().SPServices.SPFindPeoplePicker({ 
peoplePickerDisplayName: personField,
checkNames: true
});
// intiate check names - don't have to do another timeout here as we should   already
// have proper values here, simply doing it again as a secondary check
assigned.checkNames.click();
// get the users email from the SPFindPeoplePicker dictionary
acctName = assigned.dictionaryEntries[0].AccountName;

// Get user information
$().SPServices({
  operation: "GetUserProfileByName",
  async: false,
  AccountName: acctName,
  completefunc: function (xData, Status) {
    wworkPhoneExt = getUPValue(xData.responseXML, "Extension");
  }
});
 // fill out the text boxes with information
getField('input','Contact Email').value = userEmail;
getField('input','Phone Extension').value = workPhoneExt;
}
// gets the value of the called profile field
function getUPValue(x, p) {
var thisValue = $(x).SPFilterNode("PropertyData").filter(function() {
  return $(this).find("Name").text() == p;
}).find("Values").text();
return thisValue;
}
  • you may use infopath **/_vti_bin/UserProfileService.asmx ** soap method to get user profie properties. [blogs.technet.microsoft.com/anneste/2011/11/02/… – Yavuz Sep 6 '16 at 7:19
  • Yavuz - your link does not work. I am not able to use InfoPath in my environment but it I am able to tap into the soap method - it may work. Have you got an example? – garvon-77 Sep 7 '16 at 22:50
  • Correct link here blogs.technet.microsoft.com/anneste/2011/11/02/… – Yavuz Sep 8 '16 at 6:30
  • Its not going to work for me - my environment does not support the older version of InfoPath with SP 2013. Thanks anyway – garvon-77 Sep 19 '16 at 5:28
  • Is anyone familiar with the above code – garvon-77 Nov 14 '16 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.