2017-02-10 55 views
-1

我不知道編碼 - 我試圖運行下面的腳本並收到錯誤缺失)在參數lis t在線79 copyDoc.saveAndClose();copyDoc.saveAndClose();缺少)參數列表後Google腳本

塊引用

下面是文檔的URL: https://docs.google.com/document/d/1FcbVBHmCcDfjcaKXSU5UeaOD30h1d5yTyQp_s28VPzc/edit?usp=sharing

這裏是腳本。請指教。真誠的感謝。

function myFunction() { 

// [email protected] 
// Travel Request 
// Get template from Google Docs and name it 

    var docTemplate = "1FcbVBHmCcDfjcaKXSU5UeaOD30h1d5yTyQp_s28VPzc"; 

// *** replace with your template ID *** 

    var docName = "Travel_Request"; 

// When Form Gets submitted 
function onFormSubmit(e) { 
//Get information from form and set as variables 

    var email_address = "[email protected], [email protected]"; 
    var Building = e.values[5]; 
    var Request = e.values[6]; 
    var Total_Days = e.values[7]; 
    var Substitute_Needed = e.values[8]; 
    var Staff_Member_Type = e.values[9]; 
    var Coverage_Type = e.values[10]; 
    var Time_of_Day = e.values[11]; 
    var Coverage = e.values[12]; 
    var Request_Type = e.values[13]; 
    var Destination = e.values[14]; 
    var Purpose = e.values[15]; 
    var City = e.values[16]; 
    var State = e.values[17]; 
    var Purpose_is_related_to = e.values[18]; 
    var Registration = e.values[19]; 
    var Lodging = e.values[20]; 
    var Lodging_Cost = e.values[21]; 
    var Lodging_Total = e.values[22]; 
    var Meals = e.values[23]; 
    var Meals_Cost = e.values[24]; 
    var Meals_Total = e.values[25]; 
    var Mileage = e.values[26]; 
    var Other = e.values[27]; 
    var Travel_Cost = e.values[28]; 
    var Miscellanous = e.values[29]; 

// Get document template, copy it as a new temp doc, and save the Doc’s id 

    var copyId = DocsList.getFileById(docTemplate) 
    .makeCopy(docName+' for '+full_name) 
    .getId(); 

// Open the temporary document 

    var copyDoc = DocumentApp.openById(copyId); 

// Get the document’s body section 

    var copyBody = copyDoc.getActiveSection(); 

// Replace place holder keys,in our google doc template 

    copyBody.replaceText('keyDate', 
    copyBody.replaceText('keyName', 
    copyBody.replaceText('keyPosition', 
    copyBody.replaceText('keyBuilding', 
    copyBody.replaceText('keyRequest', 
    copyBody.replaceText('keyDayT', 
    copyBody.replaceText('keySubstitute', 
    copyBody.replaceText('keyStaff', 
    copyBody.replaceText('keyDay', 
    copyBody.replaceText('keyTime', 
    copyBody.replaceText('keyCoverage', 
    copyBody.replaceText('keyRequest', 
    copyBody.replaceText('keyDest', 
    copyBody.replaceText('keyPurpose', 
    copyBody.replaceText('keyCity', 
    copyBody.replaceText('keySt', 
    copyBody.replaceText('keyPurpRelated', 
    copyBody.replaceText('keyRT', 
    copyBody.replaceText('keyLND', 
    copyBody.replaceText('keyLCP', 
    copyBody.replaceText('keyLT', 
    copyBody.replaceText('keyMND', 
    copyBody.replaceText('keyMCP', 
    copyBody.replaceText('keyMT', 
    copyBody.replaceText('keyMLT', 
    copyBody.replaceText('keyOT', 
    copyBody.replaceText('keyTotalBOE', 
    copyBody.replaceText('keyMisc', 

// Save and close the temporary document 

    copyDoc.saveAndClose(); 

// copyDoc.saveAndClose() (options.cand_email);      
// Convert temporary document to PDF 

    var pdf = DocsList.getFileById(copyId).getAs("application/pdf" 

} 

回答

0

你的最後一行,

var pdf = DocsList.getFileById(copyId).getAs("application/pdf" 

似乎在結束時缺少 ')'。也許這就是失蹤)後面的參數列表

+0

謝謝。不幸的是,這並沒有解決我的問題。難道它是在腳本的開頭,它沒有找到文檔? –

0

在腳本執行結束時會自動調用saveAndClose()方法,對於每個打開的Document。可能會有所幫助:自2013年起,已棄用DocsList,請參閱https://developers.google.com/apps-script/sunset。您應該改用DriveApp

var copyId = DriveApp.getFileById(docTemplate) 
    .makeCopy(docName+' for '+full_name) 
    .getId(); 

var pdf = DriveApp.getFileById(copyId).getAs('application/pdf'); 
+0

謝謝。我應該在(docName +)和.getID()的任何實例中輸入google文檔的ID - 非常感謝您對此的任何幫助。 –

+0

不確定我是否理解正確..每次運行使用給定的名字創建模板的副本(例如,Rickey Saez的Travel_Request),並且新文檔的ID與var copy_id關聯,所以每次處理不同的ID時,我也注意到var full_name在腳本中沒有聲明 – k4k4sh1

+0

嗨K4ke4sh1,Full_ Name是指文檔模板的名稱還是收件人?我不確定。請指教。謝謝。 - Rickey –