Seems simple right ?
Well, for the current user, it is, but when looking for a specific one :
https://www.google.fr/search?rlz=1C1GCEA_enFR779FR779&ei=ihWYWorCIoHxUpT0o7AO&q=sp+js+get+user+-current&oq=sp+js+get+user
Nothing.
I'm taking inputs from a listForm using JS, one of the fields requires the client to type in an existing username
When getting the value from the list I get a collection of SP.FieldUserValue wich only contains the ID and name of the user
Is there a way to add every user in this collection to a specific group ?
What I've tried so far :
- Putting each field value directly in the group with
myGroup.get_users().addUser()- "The LoginName cannot be null/empty or 256+ caracters" - Retreiving the User using
myWeb.get_siteUserInfoList().getItemById(myField..get_lookupId());- "Cannot read property 'toString' of null" - Retreiving the User the same way then using
myWeb.ensureUser(user)to create it if it doesnt exist(even if it obviously does) - The code executes without any exeption... and nothing is put in the group
I printed out to check if every variable (group, web, user, even functions) were null, and none of them were, they all had the correct info
I'm kinda lost... any ideas ?
Here's my last code version :
ApplyPermissions() { //Many commented out code this.SetupGroup('Visiteurs_x0020__x0028_Lecture_x', 'Visiteurs'); } SetupGroup(value, suffix) { var users = this.requestData.get_item(value); var groupInfo = new SP.GroupCreationInformation(); groupInfo.set_title(this.subweb.get_title() + ' - ' + suffix); groupInfo.set_description('Ca marche presque correctement !'); var newGroup = this.subweb.get_siteGroups().add(groupInfo); var testGroup = this.web.get_siteGroups().add(groupInfo); //this.AddUsersToGroup(users, newGroup); this.AddUsersToGroup(users, testGroup); return newGroup; } AddUsersToGroup(users, group) { users.forEach((user)=>{ var userID = user.get_lookupId(); var userInfo = this.web.get_siteUserInfoList().getItemById(userID); console.log(group.get_users().addUser); this.context.load(userInfo); this.context.executeQueryAsync(()=>{ group.get_users().addUser(userInfo); //I already tried putting another Query here to save, nope }, QueryError); }); } The ultimate goal is to add the user to a subweb next, any help is extremely appreciated