1

This is first time i use people picker. I have no experince with it. I hope that somebody can help me with getting value of people picker to save it in a new item as a person in my hosted list in SharePoint online.

This is my people picker code

function initializePeoplePicker(peoplePickerElementId) {
    // Render and initialize the client-side People Picker.

    // 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'] = '151px';

this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);}

and this is the code when page starts

initializePeoplePicker('peoplePickerDiv');

and that's what I want. I want to write code instead of the question marks to send the user to the SharePoint list and att the person to person field

listItem.set_item("lfua", ????????????);
2
  • You want to add it through code? Please elaborate requirement.
    – 404
    Mar 5, 2015 at 23:24
  • thank you for helping i add some code to my question. now you can see what i want Mar 6, 2015 at 23:22

1 Answer 1

0

Please include following code:

// Query the picker for user information.
function getUserInfo() {

// Get the people picker object from the page.
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;

// Get information about all users.
var users = peoplePicker.GetAllUserInfo();



// Get the first user's ID by using the login name.
getUserId(users[0].Key);
}

// Get the user ID.
function getUserId(loginName) {
    var context = new SP.ClientContext.get_current();
    this.user = context.get_web().ensureUser(loginName);
    context.load(this.user);
    context.executeQueryAsync(
         Function.createDelegate(null, ensureUserSuccess), 
         Function.createDelegate(null, onFail)
    );
}

function ensureUserSuccess() {
    var <YOURVAR> = this.user.get_id());
    listItem.set_item("lfua", <YOURVAR>);
}

function onFail(sender, args) {
    alert('Query failed. Error: ' + args.get_message());
}
0

Your Answer

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

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