Reputation: 117
I have created a from and added some textboxed in it, And I have created a people picker which is working good, I can even select multiple users in my field, but if I chose 2 people in peoplepicker in my list is being saved only 1 person. So if I select more than 1 user in people picker like this:
In my list only first name is being saved like this:
Audienca
column is a single line of text
How Can I save both users
My people picker code is this:
My ascx
<SharePoint:ScriptLink ID="ScriptLink1" Name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink2" Name="clientforms.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink3" Name="clientpeoplepicker.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink4" Name="autofill.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink5" Name="sp.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink6" Name="sp.runtime.js" runat="server" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink7" Name="sp.core.js" runat="server" LoadAfterUI="true" Localizable="false" />
<div id="audienceSelector" style="float: left;"></div>
<div class="clear"> </div>
<div class="clear"> </div>
<div class="clear"> </div>
<div class="clear"> </div>
C# code
initializePeoplePicker('audienceSelector');//this is on top
function initializePeoplePicker(peoplePickerElementId) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['Width'] = '300px';
// Render and initialize the picker.
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
}
this is the code when i try to save my data
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = quizList.addItem(itemCreateInfo);
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.audienceSelector_TopSpan;
// Get information about interviewer
var users = peoplePicker.GetAllUserInfo();
for (var i = 0; i < 1; i++) {
user = users[0];
interviewerName = user["DisplayText"];
}
listItem.set_item("Title", $('#newTestName').val());
//listItem.set_item("Audienca", $('#audienceSelector').val().toString());
listItem.set_item("Audienca", interviewerName);
Upvotes: 2
Views: 2638
Reputation: 21
What happens if you change the users array in your For loop to use [I] instead of [0] like this:
for (var i = 0; i < 1; i++) {
user = users[i];
interviewerName = user["DisplayText"];
}
Also I would use a person or group column which will bring more functionality like presence indicatiors. Make sure that your field on the list is set to allow multiple selections in the list settings.
Upvotes: 2