This is all for SharePoint 2010. I have in my form the ability to put in a user in a people picker and then the users click a button that pulls in the user's email address and dept phone number. This works fine with any owners of the site (people who have full control), however it works with no one else. I get access denied when $(xData.responseXML) runs. I'm not sure if this can be fixed within the site collection level of if there are permissions that need to be changed in Central Admin (which is not an option). If anyone knows a fix, I'd appreciate it...or if anyone knows a better way to get another user's phone number (email works straight from people picker), I'll take that as well.
Basically what I'm doing is extracting the user's email from the people picker, using SPServices to GetUserLoginFromEmail and then using the login and SPServices GetUserProfileByName to get the phone number. Here is the full code:
function getPeople(){
var personField = "Contact Name"; // this must match the display name of the people picker field
var assigned; // value from people picker field
var userEmail; // stores the assigned's email
var userLogin; // assigned's login ie: (domain\name)
var trueLogin; // asigned's login converted for javascript ie: (domain\\name)
var workPhone; // stores assigned's work phone
// 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
userEmail = assigned.dictionaryEntries[0].Email;
// use the email to get the user's login information
$().SPServices({
operation: 'GetUserLoginFromEmail',
emailXml: "<Users><User Email='" + userEmail + "'/></Users>",
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
userLogin = $(this).attr("Login");
});
}
});
// convert the login to javascript usable login
trueLogin = userLogin.replace(/\\/g,'\\');
// Get user information
$().SPServices({
operation: "GetUserProfileByName",
async: false,
AccountName: trueLogin,
completefunc: function (xData, Status) {
workPhone = getUPValue(xData.responseXML, "WorkPhone");
}
});
// fill out the text boxes with information
getField('input','Contact Email').value = userEmail;
getField('input','Contact Phone').value = workPhone;
}
// 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;
}
When I hard coded my login and ran the page, the GetUserProfileByName worked fine. So it only seems to be the GetUserLoginFromEmail that is not working with the permissions the way they are.
Thanks for any and all help/suggestions. By the way, client-side code is my only option at this point.