TypeError:无法从未定义中读取属性“值”。 (第7行,文件“代码”)

时间:2019-01-22 00:55:03

标签: google-apps-script triggers google-form

截至今天的12:56,该脚本在过去的4年多的时间里经过了几次迭代,均达到了100%的效果。我本身不知道javascript,但是我设法将其结合在一起,并且没有任何问题。它基本上是一个Google表单,用于填充工作表,然后将数据与Doc模板合并,然后输出通过电子邮件发送给我的PDF。

我看到Trigger界面已经更新为Google的新外观,因此,它缺少了一些旧选项,但是我认为它不会破坏系统。我已在该站点上阅读了一些内容,并删除了旧触发器,并制作了一个新触发器,希望对您有所帮助,但没有成功。

Google是否更改了e.values参数?我没在他们的Stackbug网站上看到它……

这对于我的日常工作流程非常重要,并且阻止了一些人使他们的工作自动化。任何帮助是极大的赞赏。

var docTemplate = "DOCTEMPLATECODE"; //
var docName = "SG19 - Formal Offer";

// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
var todays_date = e.values[0];
var email_address = e.values[1];
var agency_name = e.values[2];
var artist_name = e.values[3];
var play_date = e.values[4];
var other_artists = e.values[5];
var stage_name = e.values[6];
var set_time = e.values[7];
var artist_fee = e.values[8];
var additional_terms = e.values[9];
var artist_camp = e.values[10];
var billing_size = e.values[11];
var expiration_date = e.values[12];
var guest_list = e.values[13];

var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName + ' for ' + artist_name + " - " + play_date)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();

var TARGET_FOLDER="TARGETFOLDERCODE";

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

copyBody.replaceText('keyAgencyName', agency_name);
copyBody.replaceText('keyArtistName', artist_name);
copyBody.replaceText('keyArtistName', artist_name);
copyBody.replaceText('keyAgencyName', agency_name);
copyBody.replaceText('keyPlayDate', play_date);
copyBody.replaceText('keyStageName', stage_name);
copyBody.replaceText('keySetTime', set_time);
copyBody.replaceText('keyArtistFee', artist_fee);
copyBody.replaceText('keyAddTerms', additional_terms);
copyBody.replaceText('keyArtistCamp', artist_camp);
copyBody.replaceText('keyBillingSize', billing_size);     
copyBody.replaceText('keyOtherArtists', other_artists);
copyBody.replaceText('keyTodaysDate', todays_date);
copyBody.replaceText('keyExpirationDate', expiration_date);
copyBody.replaceText('keyGuestList', guest_list);

// Save and close the temporary document
copyDoc.saveAndClose();

// Convert temporary document to PDF
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

var targetFolder = DriveApp.getFolderById(TARGET_FOLDER) ;
var new_pdf = DriveApp.getFileById(copyId).makeCopy(artist_name  + " - " + " 
Serenity Gathering " + " - " + " Oakdale CA " + " - "  +  play_date, 
targetFolder)
.getAs("application/pdf");

// Attach PDF and send the email
var subject = "Formal Offer " + " - " + artist_name  + " - " + " Serenity 
Gathering " + " - " + " Oakdale CA " +  " - "  +  play_date;  
var body = "Greetings, our offer for " + artist_name  +  " at " + " Serenity 
Gathering " + play_date + " is attached "; 
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, 
attachments: pdf});

// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}

0 个答案:

没有答案