我尝试在Google协作平台上创建时间跟踪工具,以便我的同事记录他们的工作时间,并满足以下需求:
- 3 buttons: One to log a timestamp, one to tally up logs, and one to view a logsheet.
- all users can see button 1, only specific email addresses can see boxes 2 & 3.
- When button 1 is pressed, logging script is run and gadget returns to button, so user can press again.
我创建了以下Google Appscript以在Gadget IEFrame中绘制按钮,点击时运行时间戳脚本,理想情况下将用户的注意力返回到按钮。
我的问题是,点击appscript小工具中的按钮后,脚本运行正常,但小工具区域变为空白。我必须刷新页面才能恢复按钮。我已经尝试通过重新加载HTML文档来结束脚本,但是OutputToHTMLFile命令似乎在我上次运行时似乎无效,即使它在首次加载页面时运行正常。有没有办法在没有按钮消失的情况下运行脚本?
以下是我的测试网站上的问题:
SendtoLog脚本:
function doGet() {
var e = Session.getActiveUser().getEmail();
if( /*e == "user1@email.com" ||*/
e == "user2@email.com" ||
e == "user3@email.com")
{
return HtmlService.createHtmlOutputFromFile('adminButtons');
}
else
{
return HtmlService.createHtmlOutputFromFile('callerButtons');
}
}
function sendToLog(e) {
var email = Session.getActiveUser().getEmail(); // Get current user
var now = new Date(); //Pull login time for user
var nowMinute
var currentDate = now;
//open spreadsheet for tracking and open the sheet for the current user
var folderID = openFolderByName("TimeTrack");
var folderToWrite = DriveApp.getFolderById(folderID);
var logSheetID = openFileByName ("Logsheet");
var logSheet = SpreadsheetApp.openById(logSheetID);
try{logSheet.setActiveSheet(logSheet.getSheetByName("Sheet1"));
logSheet.deleteActiveSheet();}
catch (e){Logger.log("Sheet1 is already deleted")};
try{logSheet.setActiveSheet(logSheet.getSheetByName(email));}
catch (e) {logSheet.insertSheet(email);}
try{logSheet.setActiveSheet(logSheet.getSheetByName("Sheet1"));
logSheet.deleteActiveSheet();}
catch (e){Logger.log("Sheet1 is already deleted")};
//get last row of the sheet so we can check what was done on the last click
var lastRow = logSheet.getLastRow();
if (lastRow < 1) // If there is no data on the sheet, this will be our first logon
var logType = "logon"; //We will assume that current logon event is a logon unless noted otherwise on spreadsheet.
else
{
var dataRange = "A1:B"+ lastRow;
var dataWithoutHeaders = logSheet.getRange(dataRange).getValues() // Pull data from the sheet for comparison
var lastLogType = logSheet.getRange("C"+lastRow).getDisplayValue(); // Pull the description of the last log event
//if last row is login, add logoff, otherwise, add logon.
switch(lastLogType){
case "logon":
var logType = "logoff";
break;
case "logoff":
var logType = "logon";
break;
default:
var logType = "Logon"; //We will assume if last entry could not be compared, this is a logon event.
break;
}//End switch
}//End else statement
logSheet.appendRow([email, currentDate, logType]); //Write email, time stamp, and log event to sheet
var e = Session.getActiveUser().getEmail();
if( /*e == "user1@mail.com" ||*/
e == "user2@mail.com" ||
e == "user3@email.com")
{
return HtmlService.createHtmlOutputFromFile('adminButtons');
}
else
{
return HtmlService.createHtmlOutputFromFile('callerButtons');
}
}//end function SendtoLog
function openFileByName (FileNameString)
{
var FileIterator = DriveApp.getFilesByName(FileNameString);
while (FileIterator.hasNext())
{
var file = FileIterator.next();
if (file.getName() == FileNameString)
{
var sheet = SpreadsheetApp.open(file);
var sheetID = sheet.getId();
}
}
return sheetID;
}
function openFolderByName (FolderNameString)
{
var FolderIterator = DriveApp.getFoldersByName(FolderNameString);
var folderFound = false;
while (FolderIterator.hasNext() || !folderFound)
{
var folder = FolderIterator.next();
if (folder.getName() == FolderNameString)
{
folderFound = true;
var folderID = folder.getId();
}
}
return folderID;
}
callerButtons HTML页面:
<div style="display:block;text-align:left"><input type="button" onclick="location.href='https://script.google.com/a/macros/mycompany.com/s/AKfycbwM842S-Y6Y18sDV7p0fZlb9LqdP6juXcMz1QFa4s6-h4w/exec';" value="Time Check-In" />
adminButtons HTML页面:
<div style="display:block;text-align:left"><input type="button" onclick="location.href='https://script.google.com/a/macros/mycompany.com/s/AKfycbwM842S-Y6Y18sDV7p0fZlb9LqdP6jueL7bXcMz1QFa4s6-h4w/exec';" value="Time Check-In" />
<br>
<div style="display:block;text-align:left"><input type="button" onclick="location.href='https://script.google.com/a/macros/mycompany.com/s/AKfycbwM842S-Y67p0fZlb9LqdP6jueL7bXcMz1QFa4s6-h4w/exec';" value="Tabulate Times" />
<br>
<div style="display:block;text-align:left"><input type="button" onclick="location.href='https://script.google.com/a/macros/mycompany.com/s/AKfycbwM842S-Y6Y18sDV7p0fZlb9LqdP6jueL7bXcMz1QFa44w/exec';" value="CSV Folder" />
答案 0 :(得分:0)
好的,所以这是一个甚至不知道如何打开开发人员控制台进行故障排除的人提出的问题。对于其他想知道如何检查Chrome中的Javascript代码的人,请按 CTRL + SHIFT + I 。
事实证明,我的一个变量是其中一个onclick
函数中的破坏引用。全部修好了!