首页 > 解决方案 > How to fetch people from a specific sharepoint group to ClientPeoplePicker in Sharepoint Online?

问题描述

I have tried using ClientPeoplePickerSearchUser. Can anybody help me out? I have followed link : http://sharepointfieldnotes.blogspot.com/2014/06/sharepoint-2013-clientpeoplepicker.html

标签: restsharepoint-onlinepeoplepicker

解决方案


You need set "SharePointGroupID" property in the code to limit search people from a specific SharePoint group in client people picker.

function search(request,response) {
    var appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
    var hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    var restSource = appweburl + "/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
    var principalType = this.element[0].getAttribute('principalType');
    $.ajax( 
    {
        'url':restSource,
        'method':'POST',
        'data':JSON.stringify({
            'queryParams':{
                '__metadata':{
                    'type':'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
                },
                'AllowEmailAddresses':true,
                'AllowMultipleEntities':false,
                'AllUrlZones':false,
                'MaximumEntitySuggestions':50,
                'PrincipalSource':15,
                'PrincipalType': principalType,
                'QueryString':request.term
                //'Required':false,
                'SharePointGroupID':23,
                //'UrlZone':null,
                //'UrlZoneSpecified':false,
                //'Web':null,
                //'WebApplicationID':null
            }
        }),
        'headers':{
            'accept':'application/json;odata=verbose',
            'content-type':'application/json;odata=verbose',
            'X-RequestDigest':requestDigest
        },
        'success':function (data) { 
            var d = data;
            var results = JSON.parse(data.d.ClientPeoplePickerSearchUser);
            if (results.length > 0) {
                response($.map(results, function (item) {
                    return {label:item.DisplayText,value:item.DisplayText}
                }));
            }            
        },
        'error':function (err) { 
            alert(JSON.stringify(err)); 
        }
    }
  );
}

推荐阅读