は、私は次のようなニーズに、私の同僚が自分の時間をログに記録するために、Googleサイト上の時間追跡ツールを作成しようとして消えました以下のGoogle Appscriptを作成してガジェットIEFrameにボタンを描画し、クリック時にタイムスタンプスクリプトを実行し、理想的にはユーザーの注意をボタンに戻します。ガスは、スクリプトガジェットでボタンがターゲットスクリプトを実行し、その後、
私の問題は、appscriptガジェットのボタンをクリックすると、スクリプトはうまく動作しますが、ガジェット領域は空白になります。私はボタンを戻すためにページをリフレッシュする必要があります。私は、HTMLドキュメントをリロードしてスクリプトを終了しようとしましたが、ページが最初にロードされたときにokを実行しても、最後に実行したときにOutputToHTMLFileコマンドが動作しないようです。ボタンが消えずにスクリプトを実行する方法はありますか?ここで
は、問題は私のテストサイト上でどのように見えるかです:
SendtoLogスクリプト:
function doGet() {
var e = Session.getActiveUser().getEmail();
if(/*e == "[email protected]" ||*/
e == "[email protected]" ||
e == "[email protected]")
{
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 == "[email protected]" ||*/
e == "[email protected]" ||
e == "[email protected]")
{
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" />