我刚开始没有经验的学习Google脚本。我在获取原始文档的新创建副本并将其发送给自己时遇到了麻烦。由于某种原因,它会继续发送原始邮件。
function Every Week() {
ScriptApp.newTrigger("Weekly")
.timeBased()
.everyDays(7)
.create();
var sheet = SpreadsheetApp.getActive();
var destFolder = DriveApp.getFolderById("xxxxxxx");
DriveApp.getFileById(sheet.getId()).makeCopy("Loads and
date"+sheet.getName(), destFolder);
var files = DriveApp.getFiles();
while (files.hasNext())
var file = files.next();
var id = file.getId();
var lastUpdated = DriveApp.getFileById(id).getLastUpdated();
var MyLink = sheet.getUrl()
var MyUser = Session.getActiveUser().getEmail();
var files = DriveApp.g
MailApp.sendEmail({ to: MyUser, subject: 'Weekly title', body: MyLink, });
} ;
我一直在获取原始模板,而不是新副本。
答案 0 :(得分:0)
尝试一下:
我认为这就是您要完成的工作。
function Weekly() {
var Found=false;
var trgs=ScriptApp.getProjectTriggers();
for(var i=0;i<trgs.length;i++){
if(trgs[i].getHandlerFunction()=="Weekly"){
Found=true;
}
}
if(!Found){
ScriptApp.newTrigger("Weekly").timeBased().everyDays(7).create();
}
var spreadsheet=SpreadsheetApp.getActive();
var destFolder = DriveApp.getFolderById("id");
var newSpreadsheet=DriveApp.getFileById(spreadsheet.getId()).makeCopy("New Title", destFolder);
var MyLink = spreadsheet.getUrl()
var MyUser = Session.getActiveUser().getEmail();
MailApp.sendEmail(MyUser,'Weekly title',MyLink);
}