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;
}
5
  • you may use infopath **/_vti_bin/UserProfileService.asmx ** soap method to get user profie properties. [blogs.technet.microsoft.com/anneste/2011/11/02/… Commented Sep 6, 2016 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? Commented Sep 7, 2016 at 22:50
  • Correct link here blogs.technet.microsoft.com/anneste/2011/11/02/… Commented Sep 8, 2016 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 Commented Sep 19, 2016 at 5:28
  • Is anyone familiar with the above code Commented Nov 14, 2016 at 2:25

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.