我正在使用GAS将数据写入电子表格,除了每次保存记录TWICE的部分外,一切都按预期工作。我不认为客户端或服务器功能是两次触发,所以它可能是我错过的其他东西。任何见解都会非常感激。谢谢!
客户端功能:
//save data
function savedata() {
var data = $('#dataSetter');
var startTime = data.find('#startTime').val();
var firstName = data.find('#firstName').val();
var lastName = data.find('#lastName').val();
var phone = data.find('#phone').val();
var email = data.find('#email').val();
var obj = $(this).parent();
var weekDate = getSuffix(obj.attr('id'));
weekDate = weekDate.replace('-', '/');
var year = getSuffix(obj.attr('class'));
var date = weekDate+'/'+year;
google.script.run.withSuccessHandler(dataSaved).setdata(office, firstName, lastName, phone, email, date, startTime);
google.script.run.withFailureHandler(onFailure).setdata(office, firstName, lastName, phone, email, date, startTime);
}
服务器功能:
//saves data
function setdata(office, firstName, lastName, phone, email, date, startTime) {
var dataSheet = dataBook.getSheets()[0];
var membersSheet = membersBook.getSheets()[0];
var membersLastRow = membersSheet.getLastRow();
var lastmemberID = membersSheet.getRange('A'+membersLastRow).getValue();
var newmemberID = memberID(lastmemberID);
membersSheet.appendRow([newmemberID, lastName, firstName, phone, email]);
}
答案 0 :(得分:2)
您正在调用setdata函数,因此应该需要双重条目。试试这个:
google.script.run.withSuccessHandler(dataSaved).withFailureHandler(onFailure).setdata(office, firstName, lastName, phone, email, date, startTime);
而不是:
google.script.run.withSuccessHandler(dataSaved).setdata(office, firstName, lastName, phone, email, date, startTime);
google.script.run.withFailureHandler(onFailure).setdata(office, firstName, lastName, phone, email, date, startTime);
答案 1 :(得分:0)
我偶尔经历过tbsi bug很多次。 它插入的行数是我要求的两倍。我用锁来保护所有代码(锁服务,你也应该使用,因为你使用getastrow等)所以我知道代码并没有并行运行。