问题描述
我正在编写一个脚本,它包含从一个组获得成员,
脚本标识邮件是否是组邮件或成员电子邮件,
但在我的工作中,我们
这里是脚本
函数getGroupUsers (){
var group = sheet.getActiveRange()。getValue();
var members = AdminDirectory.Members.list(group).members;
for(var i = 1; i< members.length; i ++){
var member = members [i];
var caseUser = sheet.getRange(i + 1,1);
var caseGroupe = sheet.getRange(i + 1,2);
var lastRange = sheet.getRange(sheet.getLastRow(),3);
// var caseGroupe2 = sheet.getRange(i + 1,4);
switch(member.type){
'USER':
Logger.log('%s是用户',member.email);
caseUser.setValue(member.email);
休息;
case'GROUP':
Logger.log('%s is a group',member.email);
// var group = GroupsApp.getGroupByEmail(member.email);
caseGroupe.setValue(member.email);
休息;
默认值:
Logger.log('Nothing');
}
工作正常,作为第二栏的组,但我需要它们自动扩展,就像我在开始循环中所做的一样,但我不确定它是如何工作的,我在循环中尝试了循环,但是当我得到组的成员时,只有一个写在案例中,而不是所有。
如果您需要更多信息,或者您需要我解释一个您不确定要理解的观点,请告诉我
我修改了一下你的代码。
我做了类似的事情,但是我没有在循环中创建循环,而是创建了一个新函数,然后递归调用它。这是为了处理一个小组会有另一个小组的情况,而另一个小组将会有另一个小组作为成员。
函数getGroup(){
var sheet = SpreadsheetApp.getActiveSpreadsheet()。getActiveSheet();
var cell = sheet.getActiveCell();
var group = sheet.getActiveCell()。getValue();
var subgroup = 1;
getMembers(group,subgroup,cell,sheet);
cell.activate();
$ b函数getMembers(group,subgroup,cell,sheet)
{
var col = cell.getColumn()+ subgroup;
var row = cell.getRow()+1;
尝试{
var members = AdminDirectory.Members.list(group).members;
if(!members)
{
return 0;
}
}
catch(e)
{
return;
}
var offset = 0;
(成员中的var成员){
var newcell = sheet.getRange(row ++,col);
newcell.setValue(members [member] .email);
if(members [member] .type =='GROUP'){
newcell.activate();
offset = getMembers(members [member] .email,subgroup,sheet.getActiveCell(),sheet);
row = row + offset;
}
}
return member.length + offset;
}
我希望这可以帮助您达成目标。
I'm working on a script which consist in get members from a group,the script identifies if the mail whether is a group email or a member email,but, in my job, we have groups in groups !
So here's the script
function getGroupUsers() {
var group = sheet.getActiveRange().getValue();
var members = AdminDirectory.Members.list(group).members;
for (var i = 1; i < members.length; i++) {
var member = members[i];
var caseUser = sheet.getRange(i+1, 1);
var caseGroupe = sheet.getRange(i+1, 2);
var lastRange = sheet.getRange(sheet.getLastRow(), 3);
// var caseGroupe2 = sheet.getRange(i+1, 4);
switch (member.type) {
case 'USER':
Logger.log('%s is a user', member.email);
caseUser.setValue(member.email);
break;
case 'GROUP':
Logger.log('%s is a group', member.email);
//var group = GroupsApp.getGroupByEmail(member.email);
caseGroupe.setValue(member.email);
break;
default:
Logger.log('nothing');
}
That's workin, as groups going in the second column, but i need them to be auto extended , like what I'm doing with the loop in the begining, but I'm not sure how can it works, I tried loops in loops but when I get members of the group there's only one written in the case instead of all.
If you need more information, or you need me to explain a point you're not sure to understand just tell me
I modified your code a little bit. The thing that you mentioned about doing a loop inside a loop was correct.
I did something similar but instead of having a loop inside a loop, i created a new function, and then call it recursively. This was to handle the case where a group would have another group, and that other group would have another group as member.
function getGroup(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getActiveCell();
var group = sheet.getActiveCell().getValue();
var subgroup = 1;
getMembers(group, subgroup, cell, sheet);
cell.activate();
}
function getMembers(group, subgroup, cell, sheet)
{
var col = cell.getColumn() +subgroup;
var row = cell.getRow() +1;
try{
var members = AdminDirectory.Members.list(group).members;
if(!members)
{
return 0;
}
}
catch (e)
{
return;
}
var offset = 0;
for(var member in members){
var newcell = sheet.getRange(row++,col);
newcell.setValue(members[member].email);
if(members[member].type == 'GROUP'){
newcell.activate();
offset = getMembers(members[member].email,subgroup , sheet.getActiveCell() ,sheet);
row = row + offset;
}
}
return member.length + offset;
}
I hope this helps in what you intended to do.
这篇关于从群组电子邮件(群组中的群组)应用程序脚本和电子邮件中提取群组电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!