SharePoint Client People Picker Control Helper

The SharePoint people picker client-side control is a bit of an opaque beast, many times when you’re doing a client-side customisation you might want to Add or Remove person or group entities or otherwise examine the list of entities the user has selected.


The good news is that there is an API of sorts found in clientpeoplepicker.js, as long as you can target the specific people picker control you’re interested in.

The samples that follow are written in TypeScript but are easily converted to JavaScript, see the GIST at the end of the post for the complete module.

Get a People Picker Control Instance.

	public static getControl(internalColumnName) : SPClientPeoplePicker {
		if (!internalColumnName || !internalColumnName.length) {
			return null;
		var ppTopLevelDiv:JQuery = $(".sp-peoplepicker-topLevel[id^='" + internalColumnName + "_']");
		if (!ppTopLevelDiv.length) return null;
		var control = SPClientPeoplePicker.SPClientPeoplePickerDict[ppTopLevelDiv[0].id];
		return control;

This yields the SharePoint people picker control for the (Internal) column name specified.

Clear all Entities from a People Picker Control.

	public clear(): void {
		if (!this._control || !this._control.ResolvedListElementId) return;

			.each( (i:number, el:HTMLElement ) => {

Remove an Entity from a People Picker Control.

	public removeEntity(entityKey : string): boolean {
		if ( 	(!entityKey || !entityKey.length) ||
				(!this._control || !this._control.ResolvedListElementId) )return;
		var removed: boolean = false;
			.each( (i:number, el:HTMLElement ) => {
				if (('membership|'+entityKey+'_') !== -1) ||
						('_'+entityKey+'_') !== -1) ) {
					removed = true;
		return removed;

Add a Resolved Entity to a People Picker Control.

	public addResolvedEntity(entityKey: string, search?: boolean): void {
		if ( 	(!entityKey || !entityKey.length) ||
				(!this._control || !this._control.ResolvedListElementId) )return;
		this._control.AddUserKeys(entityKey, search);

The supplied entityKey is either a user email address (Office365) or user account name (On-Premises) or a SharePoint Group name

Add an Unresolved Entity to a People Picker Control.

	public addUnresolvedEntity(entityText: string): void {
		if ( 	(!entityText || !entityText.length) ||
				(!this._control || !this._control.ResolvedListElementId) )return;
		var ppUserInput = $(document.getElementById(this._control.EditorElementId));

This is equivalent to the user typing into the edit box

Return all Entity Info from the People Picker Control.

	public getEntities(): ISPClientPeoplePickerEntity[] {
		var userInfo = this._control.GetAllUserInfo();
		return userInfo || ([] as ISPClientPeoplePickerEntity[]);


Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.