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.

4 Answers 4

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. Commented Dec 2, 2013 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); Commented Dec 2, 2013 at 4:49
0

Actually, spservices has a solution.

Here is the documentation.

0

Adding a processed user works ok.

var usrObj = {"Key" : displayName, "Description" : "sAMAccountName=" + user.UserName, "DisplayText" : user.Title, "EntityType" : "User", "ProviderDisplayName" : "ADFS", "ProviderName" : "LDAPCP", "IsResolved" : true, "EntityData" : {"Email" : user.EMail, "DisplayName" : user.Title}, "MultipleMatches" : []};
spPeoplePicker.AddProcessedUser(usrObj, true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.