I am trying to programmatically add people to a People picker set to accept multiple people. I can't seem to get it to work. I have tried:
fd.field('People').value = [9, 17];
fd.field('People').value = ["9", "17"];
var array = [9, 17];
for (i = 0; i < array.length; i++) {
fd.field('People').value[i] = array[i];
}
Hello @smithme,
You need to use either Display Name or Email, like this:
fd.field('PeoplePicker').value = ['Elizabeth Holmes', 'Jane Doe']
What I am trying to do with this is duplicate a list item. This list item has a People picker that allows multiple people. When I query the template list item using:
var web = new Web('https://mysharepoint.sharepoint.com/');
web.lists.getByTitle('Tickets').items.filter("TemplateId eq " + temp + " and TemplateTickets eq 'Parent'").getAll().then(function(items) {
items.forEach(function(item, index) {
console.log(item);
// Set field values
});
});
In the People picker (from the template list item) I get:
PeopleId: [9, 17]
PeopleStringId: ["9", "17"]
That means, I will have to query SharePoint for each user to get the name or email address. I am trying to do that with:
var web2 = new Web('https://mysharepoint.sharepoint.com/');
web2.getUserById(9).then(function(user) {
// do something with user
});
or
var web2 = new Web('https://mysharepoint.sharepoint.com/');
var user = web2.getUserById(9);
console.log(user);
With the first example I get the error the "then is not a function". With the second example I get "user is a promise undefined".
How do I turn the SharePoint index (ID) into the user email or name?
I also tried to query the user list at:
https://mysharepoint.sharepoint.com/_catalogs/users/detail.aspx
But this doesn't seem to find anything. I don't get any errors.
I am getting this to work but I am getting different answer depending on the subsite.
var id = 17;
var web = new Web('https://mysharepoint.sharepoint.com/sites/subsite');
web.getUserById(id).get().then(u => {
console.log(u);
});
@smithme,
Why do you need to define a site url?
You can get user email:
var userID = 19;
pnp.sp.web.getUserById(userID7).get().then(function(user){
console.log(user.Email)
})