I am needing to get the value of what was entered in people picker field, and automatically populate this value into a second people picker field on save. (on my list I need to display both the persons name and their phone in separate columns).
Most of the examples I have found so far are can be used to successfully populate multiple people picker fields with the current ID of the person that is logged on, but obviously are not what I need as the ID does not necessarily need to be the same as the person currently logged on.
(Examples are here: https://social.msdn.microsoft.com/Forums/office/en-US/872785c7-4179-488e-9239-1a9c81d48eda/set-the-column-value-to-current-userid-if-check-box-is-checked?forum=sharepointdevelopmentprevious)
I have cobbled the following Web Part script together of all the different techniques I have discovered so far, using a column name of Uid, but none is working.
<html>
<script src="https://oursites.../jquery-1.11.3.js"></script><script>
// <![CDATA[
$(document).ready(function () {
alert('Executing OK');
});
function PreSaveAction(){
(window.jQuery || document.write('<script src="https://oursites..../jquery.SPServices-0.7.2.min.js"><\/script>'));
(window.jQuery || document.write('<script src="https://oursites.../jquery-1.11.3.js"><\/script>'));
alert('in save');
var ppDiv = $("[id$='ClientPeoplePicker'][title='Uid']");
alert(ppDiv);
var ppEditor = ppDiv.find("[title='Uid']");
alert(ppEditor);
var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
alert(spPP);
var ppEditorval = ppEditor.val();
alert(ppEditorval);
var fieldName = "Uid";
var _PeoplePicker = $("div[title='" + fieldName + "']");
alert(_PeoplePicker);
var _PeoplePickerTopId = _PeoplePicker.attr('id');
alert(_PeoplePickerTopId);
var _PeoplePickerEditer = $("input[title='" + fieldName + "']");
alert(_PeoplePickerEditer);
var ppEdit = _PeoplePickerEditer.val();
alert(ppEdit);
var PickerTitle = "Uid";
var PickerDiv = $('[id$="ClientPeoplePicker"][title="' + PickerTitle + '"]');
alert(PickerDiv);
var PickerEditor = PickerDiv.find('[title="' + PickerTitle + '"]');
alert(PickerEditor);
var PickerInstance = SPClientPeoplePicker.SPClientPeoplePickerDict[PickerDiv[0].id];
alert(PickerInstance);
var ppchk = $('td nobr:contains("' + PickerTitle + '")').eq(0).closest('tr').next('td').text();
alert(ppchk);
alert('stop');
return false;
};
// ]]></script>
</html>
The following are the values from the Trace Alerts:
- All fields have a value of object Object] except for the following fields:
- ppEditorval, ppEdit and ppchk which are all blanks
- _PeoplePickerTopId which has a value of Uid......$ClientPeoplePicker
Additionally I also tried the following code as well
var salesRep = $().SPFindPeoplePicker({
peoplePickerDisplayName: "Uid"
});
var sr = salesRep.currentValue;
alert(sr);
var sruid = salesRep.SPUserid;
var sruidtitle = salesRep.row.find("span[class='ms-entity-resolved']").attr("title");
var pp = $().SPFindPeoplePicker({ peoplePickerDisplayName: "Uid" });
alert(pp);
But none of this code worked - I received the error message
SCRIPT438: Object doesn't support property or method 'SPFindPeoplePicker'
Help! How do I get the value of a People Picker field?