0

I have come across the client side people picker javascript. Right now the people picker accepts all users. Is there any way we can point it to a SharePoint Group. I only want users that are present in a SharePoint Group to be selected as a value for the people picker. Kindly help.

0

You could add a attribute schema['SharePointGroupID'] = 8;

Full demo:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
<script type="text/javascript" src="_layouts/15/clienttemplates.js"></script>  
<script type="text/javascript" src="_layouts/15/clientforms.js"></script>  
<script type="text/javascript" src="_layouts/15/clientpeoplepicker.js"></script>  
<script type="text/javascript" src="_layouts/15/autofill.js"></script>
<div>  
    <label>User Name:</label>  
    <div id="_UserName"></div>  
</div>  
<input type="button" id="button" value="submit">
<script>
$(document).ready(function() {  
    initializePeoplePicker("_UserName");  

});  
function initializePeoplePicker(peoplePickerElementId) {  
    var schema = {};  
    schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';  
    schema['SearchPrincipalSource'] = 15;  
    schema['ResolvePrincipalSource'] = 15;  
    schema['AllowMultipleValues'] = false;  
    schema['MaximumEntitySuggestions'] = 50;  
    schema['Width'] = '280px';  
    schema['SharePointGroupID'] = 8;
    this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);  
}
$("#button").click(function (){
ensureUser()
})
function ensureUser() {  
var peoplePickerTopDivId = $('#_UserName').children().children().attr('id');  
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerTopDivId];  
var users = peoplePicker.GetAllUserInfo();  
var arryuser = users[0];  
  console.log(arryuser)
} 
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.