Get and Set the Users or Names on SharePoint 2013 People Picker (Person Group) field on Custom List Forms using JQuery.
The SharePoint 2013 Client People Picker on Custom List forms is different from OOB control.
The "div" structure is different when compare with both. So we have to write different script on custom forms.
The below code will give an example to get and set the values for Client People Picker or Person Group Field on Custom List forms.
// Get People Picker Values function getEditorPeoplePickerValues(fieldName) { // Field Title editorNames = ""; var _PeoplePicker = $("div[title='" + fieldName + "']"); var _PeoplePickerTopId = _PeoplePicker.attr('id'); var ppobject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId]; editorsInfo = ppobject.GetAllUserInfo(); var i; for (i = 0; i < editorsInfo.length; ++i) { editorNames += editorsInfo[i].DisplayText + ";#"; } } // Set People Picker Values function SetAndResolvePeoplePicker(fieldName, userAccountName) { // alert(userAccountName); var _PeoplePicker = $("div[title='" + fieldName + "']"); var _PeoplePickerTopId = _PeoplePicker.attr('id'); var _PeoplePickerEditer = $("input[title='" + fieldName + "']"); userAccountName.split(";#").forEach(function (part) { if (part !== "" && part !== null) { // alert(part); _PeoplePickerEditer.val(part); var _PeoplePickerOject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId]; _PeoplePickerOject.AddUnresolvedUserFromEditor(true); } }); } // How to use the above function on our code call direct function to get values. but to set values we have to create an array with names. var editorNames = ""; getEditorPeoplePickerValues("Field Title"); SetAndResolvePeoplePicker("Field Title", editorNames );
when refresh the URL this method not working
ReplyDelete