此腳本運行良好將近一年。這兩個觸發器都是「On Form Submit」。 大約一個星期前,這兩個函數開始製作重複:兩個相同的電子郵件,兩個相同的日曆事件。我在這裏經歷了一堆帖子&我無法得到如何擺脫這個問題。我不是程序員,下面的代碼來自不同的來源。最近添加LockService但沒有成功。 任何人都可以解釋代碼有什麼問題嗎? 謝謝。腳本正在創建副本:創建Google日曆事件表單提交
function BOOKemail(email, subject, message, options)
{
var lock = LockService.getPublicLock();
var success = lock.tryLock(5000);
if (!success) {
Logger.log('tryLock failed to get the lock');
return
}
var email = "[email protected]"
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var lr = rows.getLastRow();
var subject = "Request: "+sheet.getRange(lr,2).getValue()+" "+sheet.getRange(lr,1).getValue();
var message = "Issue: "+sheet.getRange(lr,3).getValue()+" "+"Employee name: "+sheet.getRange(lr,4).getValue();
var options = {name:"ABC"};
MailApp.sendEmail(email, subject, message);
lock.releaseLock();
}
function createEvent(title, date, desc)
{
var lock = LockService.getPublicLock();
var success = lock.tryLock(5000);
if (!success) {
Logger.log('tryLock failed to get the lock');
return
}
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var lr = rows.getLastRow();
var title = sheet.getRange(lr,1).getValue()+" "+"Request: "+sheet.getRange(lr,2).getValue()+" "+"Issue: "+sheet.getRange(lr,3).getValue()+" [F]";
var desc = "Issue: "+sheet.getRange(lr,3).getValue()+" "+"Employee name: "+sheet.getRange(lr,4).getValue();
var cal = CalendarApp.getCalendarsByName('ABC') [0];
var date = new Date();
var event = cal.createAllDayEvent(title, date, {description : desc});
lock.releaseLock();
};
您可能需要考慮搜索問題跟蹤器並報告它:[Apps Script Issue Tracker](https://code.google.com/p/google-apps-script-issues/issues/list) – 2015-02-12 02:43:33
爲什麼不能將這些功能結合起來? – corn3lius 2015-02-12 02:44:56