In this article we are going to see how to use client side people picker in SharePoint 2013.
The SharePoint people picker is already available in SharePoint as a server control, but now a days all are moving to client side based code since office 365 supports only client side. So we need to know how to be use people picker in client side.
Required JavaScript Library
The client side people works depends on multiples SharePoint JavaScript library,
- <script src="/_layouts/15/sp.runtime.js"></script>
- <script src="/_layouts/15/sp.js"></script>
- <script src="/_layouts/15/1033/strings.js"></script>
- <script src="/_layouts/15/clienttemplates.js"></script>
- <script src="/_layouts/15/clientforms.js"></script>
- <script src="/_layouts/15/clientpeoplepicker.js"></script>
- <script src="/_layouts/15/autofill.js"></script>
- <script src="_layouts/15/sp.core.js"></script>
Steps to Implement People Picker
Step 1
Refer the above JavaScript files in your page.
Step 2
Create a div tag in your page.
- <div id=’peoplepicker’ /></div>
Step 3
Initialize the people picker on page load
- $(document).ready(function() {
- initializePeoplePicker(’peoplepicker’, false, ‘People Only’, 44);
- function initializePeoplePicker(peoplePickerElementId, AllowMultipleValues, PeopleorGroup, GroupID) {
- // Create a schema to store picker properties, and set the properties.
- var schema = {};
- schema['SearchPrincipalSource'] = 15;
- schema['ResolvePrincipalSource'] = 15;
- schema['MaximumEntitySuggestions'] = 50;
- schema['Width'] = '280px';
- schema['AllowMultipleValues'] = AllowMultipleValues;
- if (PeopleorGroup == 'PeopleOnly') schema['PrincipalAccountType'] = 'User';
- else schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
- if (GroupID > 0) {
- schema['SharePointGroupID'] = GroupID
- }
- // Render and initialize the picker.
- // Pass the ID of the DOM element that contains the picker, an array of initial
- // PickerEntity objects to set the picker value, and a schema that defines
- // picker properties.
- this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
- }
- });
Note - Usage of the parameters values
Love ThakkerPosted Sep 8, 2019, 7:29 AM
Hi. Nice blog. just one update I will suggest is you have not defined UserID in getUserInfo() method. I was getting error there.
sarahPosted Dec 7, 2018, 9:50 AM
Hi, can you please explain to me how to use this client side picker. My question is posted here: https://sharepoint.stackexchange.com/questions/253927/client-people-picker-value-for-workflow I basically want to get the values of the fields I have (filtered by groups only) to use the values in a sharepoint designer workflow but the values are always null... I was thinking of maybe using the PreSave function to save the values like this: function PreSaveItem(){alert('1'); if ("function"==typeof(PreSaveAction)) { return PreSaveAction(); } return true; } function PreSaveAction() { try{ alert('hi'); getUserInfo("AcademyFixedPermissions_5814f08e-a7ab-4c8e-bb73-72d58fd452dc_$ClientPeoplePicker"); return true; } catch(err) { alert('Please report this error 2: ' + err); return false; } } but the presave function is not even firing - any help pleasE?
Tiago FelicianoPosted Oct 17, 2018, 10:09 AM
Hello great post, i just have a question how do you get the people from this custom people picker? Im asking because im having trouble making an insertion from the data present in the div to a sharepoint 2013 people column.
Piyush AgarwalPosted Mar 7, 2018, 6:04 AM
This is really help full. However will this work if I have multiple people picker on the same page....
Kukdai DPosted Oct 7, 2017, 4:39 PM
People picker works you can search and find users but following errors comes up in the console for each user resolved and if you resolve multiple user then it says you are not allowed to enter more than one name When i type 3 words in the textbox following are the console errors 1. Uncaught ReferenceError: RemoveCssClassFromElement is not defined at HTMLInputElement.SPClientPeoplePicker_OnEditorBlur (clientpeoplepicker.js:1) 2. Uncaught RangeError: Maximum call stack size exceeded at ULSObject.ULSOnError [as OriginalOnError] (init.js?rev=RIl4brNTuKjQszVd+c1CnQ==:1) at ULSSendExceptionImpl (init.js:12) at ULSObject.ULSOnError [as OriginalOnError] (init.js?rev=RIl4brNTuKjQszVd+c1CnQ==:1) at ULSSendExceptionImpl (init.js:12) at ULSObject.ULSOnError [as OriginalOnError] (init.js?rev=RIl4brNTuKjQszVd+c1CnQ==:1) at ULSSendExceptionImpl (init.js:12) at ULSObject.ULSOnError [as OriginalOnError] (init.js?rev=RIl4brNTuKjQszVd+c1CnQ==:1) at ULSSendExceptionImpl (init.js:12) at ULSObject.ULSOnError [as OriginalOnError] (init.js?rev=RIl4brNTuKjQszVd+c1CnQ==:1) at ULSSendExceptionImpl (init.js:12)