here is my purpose: I want to create a script that, when you select different user's group, it shows you every member of these groups. Also ( later), it will permit to show only users that are in all the selected groups.
Here is my problem: I have a variable that store one by one users that are in groups i selected. But if a user is in two group he will be stored twice. (The issue will be met again in second part of my script sooo....)
Here is my code:
function membreAssocGroupe()
{
var email = " ";
var groupes = ["[email protected]","[email protected]","[email protected]"]; // this is groups i selected
//checking in "var groupes" all values that are registered.
for (var g in groupes) {
//opening the group by the e-mail and getting all the users in "var users" of the group.
var group = GroupsApp.getGroupByEmail(groupes[g]);
var users = group.getUsers();
//for all the users get in "var users", we will copy their e-mail in "var e-mail"
for (var u in users){
//if the user e-mail is already saved in "var email", go to the next user.
if(email.indexOf(u)>0)
{
continue;
}
//if the user e-mail is not saved, copy it in "var email".
else
{
email = email + users [u] .getEmail () + email.indexOf(u) + " ";
}
}
//to see what i get
var s = s + "\n" + "Group " + groupes[g] + " has " + users.length +
" members:\n " + email + "\n \n ";
}
Logger.log(s);
}
As you now understand, the problem is this part(all entry get -1 in this operation):
if(email.indexOf(u)>0)
{
continue;
}
I tried many things:
if(email.toString().match(u)==u)
if(email.match(u)==u.toString())
if(email.toString().match(u.toString())==u.toString())
if(email.toString().match(u)==u.toString())
etc... (This way worked for cells in spreadsheet, but no way to make it works here)
But also findText and other functions i don't even remember.
As you can see (because of my way to explain the problem, and my shitty code :p), i'm a newbie, that tries hard, and finally succeed by learning little by little. If you can tell me the function i should use, and why its is better than others, i would appreciate it a lot.