【发布时间】:2020-01-23 07:23:56
【问题描述】:
我正在尝试使用 google 应用程序脚本通过其电子邮件地址获取组。这里只有一行代码很重要。
有问题的行是:
var WSGroup = GroupsApp.getGroupByEmail("Group_Email_Address@domain.com");
我知道电子邮件地址是正确的。我知道它的拼写正确。我在管理控制台中与出色的 Google 帮助台人员一起打开了一张票,并确认有问题的组与我知道正在工作的另一个组具有相同的设置。我的问题是这个。当相同的代码会找到具有相同权限设置的任何其他组时,为什么代码找不到该组。在我的头反复撞到墙上造成永久性损坏之前,我们将不胜感激。
function getGroups(){
//gets the current users email address then checks it against all the groups listed below.
//When the user is found in that group the proper excel sheet gets their time stamp and their doc is moved to the right folder.
var check = checkTimes();
//if(check == 1) {
// return 0;
//}
//else {
var user = Session.getActiveUser().getEmail();
try {
//the groups
var CACGroup = GroupsApp.getGroupByEmail("group1@domain.com");
var HSGroup = GroupsApp.getGroupByEmail("group2@domain.com");
var JHGroup = GroupsApp.getGroupByEmail("group3@domain.com");
var JSGroup = GroupsApp.getGroupByEmail("group4@domain.com");
var CSGroup = GroupsApp.getGroupByEmail("group5@domain.com");
var WSGroup = GroupsApp.getGroupByEmail("group6@domain.com"); \\var WSGroup using group6@domain is the line in question.
}
catch(e){
DocumentApp.getUi().prompt("There was an error with your group memberships! Report this to tech! Error: " + e);
}
var doc = DocumentApp.getActiveDocument();
var docID = doc.getId();
//If user is in CAC group timestamp the CAC excel sheet then move the document to the CAC signed docs folder.
try{
if(CACGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 1');
setStatus(user, googleSheet, doc);
}
if(HSGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 2');
setStatus(user, googleSheet, doc);
}
if(JHGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 3');
setStatus(user, googleSheet, doc);
}
if(JSGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 4');
setStatus(user, googleSheet, doc);
}
if(CSGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 5');
setStatus(user, googleSheet, doc);
}
if(WSGroup.hasUser(user)){
var googleSheet = SpreadsheetApp.openById('ID of spreadsheet 6');
setStatus(user, googleSheet, doc);
}
}
catch(e){
var prompt = 'There was an issue accessing the excel sheet for your building!' ;
DocumentApp.getUi().alert(prompt);
}
var prompt = 'Document sent to your main office!';
DocumentApp.getUi().alert(prompt);
//}
}
域中的任何用户都应该能够找到该组并查看其成员。我已经在 admin.google.com 和 groups.google.com 中确认了这些设置。相同的代码可以找到其他组,因此已经允许并打开了必要的 API。
【问题讨论】:
-
考虑修剪你的代码。其中很大一部分与所提出的问题无关。请看sscce.org
标签: google-apps-script google-groups