Tuesday, November 17, 2015

Using client people picker

 initializePeoplePicker('<peoplePickerDivId>', "");

People picker values can be read by

        var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv1_TopSpan;
        var users = peoplePicker.GetAllUserInfo();
        var usersArr = new Array();
        var userInfo = '';
        for (var i = 0; i < users.length; i++) {
            usersArr.push(SP.FieldUserValue.fromUser(users[i].Key));
            alert(SP.FieldUserValue.fromUser(users[i].Key).get_lookupValue());
        }

function initializePeoplePicker(peoplePickerElementId, strUser) {
    var schema = {};
    schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
    schema['SearchPrincipalSource'] = 15;
    schema['ResolvePrincipalSource'] = 15;
    schema['AllowMultipleValues'] = true;
    schema['MaximumEntitySuggestions'] = 50;
    schema['Width'] = '280px';
    if (strUser != "") {
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
        var peoplePicker = eval("this.SPClientPeoplePicker.SPClientPeoplePickerDict." + peoplePickerElementId + "_TopSpan");
        peoplePicker.AddUserKeys(strUser);
    } else {
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
    }
}

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...