4

I want set the value to the people picker control which is multi allowed.

I have a code which assigns only single value to it, which is as below:

    $(document).ready(function () {
        alert('Hello');
        SetAndResolvePeoplePicker("Members","domain\\user");
    });

    function SetAndResolvePeoplePicker(fieldName, userAccountName) {

        var controlName = fieldName;

        var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");

        var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");

        var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];

        peoplePickerEditor.val(userAccountName);


        spPeoplePicker.AddUnresolvedUserFromEditor(true);
    }

All things I have applied in is jslink.

3

Found the answer:

Just simply call the function multiple times.

Such as:

$(document).ready(function () {
    alert('Hello');
    SetAndResolvePeoplePicker("Members","domain\\user0");
    SetAndResolvePeoplePicker("Members","domain\\user1");
    SetAndResolvePeoplePicker("Members","domain\\user3");
});

It will add all the users to people picker. Hope this helps to other also...!!! :-)

1
  • 1
    Please make sure to remember to mark your answer as correct it helps keep the Q&A tidy and people to find the answer. – Hugh Wood Dec 2 '13 at 14:12
2

Try adding values directly to people picker object, not through html input.

Replace this

peoplePickerEditor.val(userAccountName);
spPeoplePicker.AddUnresolvedUserFromEditor(true);

With this

spPeoplePicker.AddUserKeys(userAccountName);

AddUserKeys accepts ";" separated list of domain names, adds them to people picker and tries to resolve it.

1
  • Thanks for answering, but the solution you suggested is not working, it throws error Object doesn't support property or method 'AddUserKeys' on the statement spPeoplePicker.AddUserKeys(userAccountName); – users1100 Dec 2 '13 at 4:49
0

Actually, spservices has a solution.

Here is the documentation.

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.