我正在尝试使用键值填写表单,然后将表单保存以便稍后在我的驱动器中的文件夹中打印。但是脚本一直给我错误“e”没有定义。我不明白为什么。
>function myfunction(e) {
var docTemplate = "1pKwW-RcjaVV8xmm00hWDx1u2QxzQwaSjPJwVY2ux2nI";
var docName = "Form";
var full_name = "Form";
function onFormSubmit(e) {}
var Assign_To_1 = e.value[2];
var Assign_To_2 = e.value[3];
var Timestamp = e.values[0];
var Date_Of_Request = e.value[1];
var Requested_By = e.value[7];
var Principal_Approval = e.value[5];
var Urgency = e.value[4];
var Building_Room_Number = e.value[10];
var Description_of_Work_To_Be_Done = e.value[6];
var Parts_Needed = e.value[8];
var Parts_In_Stock = e.value[9];
var Invoice_Number = e.value[10];
var Completed_Signature = e.value[22];
var Incomplete_Signature = e.value[23];
var On_Hold_Signature = e.value[24];
var Estimated_Hours = e.value[14];
var Number_Of_Employees_To_Complete = e.value[18];
var Budget = e.value[11];
var Follow_Up = e.value[16];
var Overtime = e.value[15];
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+' for '+full_name)
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
copyBody.replaceText('KeyAssignedTo1',Assign_To_1);
copyBody.replaceText('KeyAssignedTo2',Assign_To_2);
copyBody.replaceText('KeyTimestamp',Timestamp);
copyBody.replaceText('KeyDateOfRequest',Date_Of_Request);
copyBody.replaceText('KeyRequestedBy',Requested_By);
copyBody.replaceText('KeyPrincipalApproval',Principal_Approval);
copyBody.replaceText('KeyUrgency',Urgency);
copyBody.replaceText('KeyBuildingRoomNumber',Building_Room_Number);
copyBody.replaceText('KeyDescriptionofWorkToBeDone',Description_of_Work_To_Be_Done);
copyBody.replaceText('KeyPartsNeeded', Parts_Needed);
copyBody.replaceText('KeyPartsInStock', Parts_In_Stock);
copyBody.replaceText('KeyInvoiceNumber', Invoice_Number);
copyBody.replaceText('KeyCompletedSignature', Completed_Signature);
copyBody.replaceText('KeyIncompleteSignature', Incomplete_Signature);
copyBody.replaceText('KeyOnHoldSignature', On_Hold_Signature);
copyBody.replaceText('KeyEstimatedHours', Estimated_Hours);
copyBody.replaceText('KeyNumberOfEmployeesToComplete', Number_Of_Employees_To_Complete);
copyBody.replaceText('KeyBudget', Budget);
copyBody.replaceText('KeyFoolowUp', Follow_Up);
copyBody.replaceText('KeyOvertime', Overtime);
copyDoc.saveAndClose();
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
var doc = DocsList.getFileById(copyId);
var folders = doc.getParents();
var newFolder=DocsList.getFolder(WorkOrderForms);
doc.addToFolder(WorkOrderForms);
var docParentFolder=folders[0];
doc.removeFromFolder(docParentFolder);
}
请帮助!
答案 0 :(得分:0)
在评论中已经解决了一些问题,但我最初没有看到最大的问题:你的主要功能实际上是onFormSubmit,但它在myFunction函数中被“隐藏”......
请像下面一样重写它并设置你的触发器来运行onFormSubmit,因为main函数现在有一个不同的名字......
var docTemplate = "1pKwW-RcjaVV8xmm00hWDx1u2QxzQwaSjPJwVY2ux2nI";
var docName = "Form";
var full_name = "Form"; // you can keep these declarations as global variables
function onFormSubmit(e) { // this is the real function starting point
var Assign_To_1 = e.value[2];
var Assign_To_2 = e.value[3];
var Timestamp = e.values[0];
var Date_Of_Request = e.value[1];
var Requested_By = e.value[7];
var Principal_Approval = e.value[5];
var Urgency = e.value[4];
var Building_Room_Number = e.value[10];
var Description_of_Work_To_Be_Done = e.value[6];
var Parts_Needed = e.value[8];
var Parts_In_Stock = e.value[9];
var Invoice_Number = e.value[10];
var Completed_Signature = e.value[22];
var Incomplete_Signature = e.value[23];
var On_Hold_Signature = e.value[24];
var Estimated_Hours = e.value[14];
var Number_Of_Employees_To_Complete = e.value[18];
var Budget = e.value[11];
var Follow_Up = e.value[16];
var Overtime = e.value[15];
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+' for '+full_name)
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
copyBody.replaceText('KeyAssignedTo1',Assign_To_1);
copyBody.replaceText('KeyAssignedTo2',Assign_To_2);
copyBody.replaceText('KeyTimestamp',Timestamp);
copyBody.replaceText('KeyDateOfRequest',Date_Of_Request);
copyBody.replaceText('KeyRequestedBy',Requested_By);
copyBody.replaceText('KeyPrincipalApproval',Principal_Approval);
copyBody.replaceText('KeyUrgency',Urgency);
copyBody.replaceText('KeyBuildingRoomNumber',Building_Room_Number);
copyBody.replaceText('KeyDescriptionofWorkToBeDone',Description_of_Work_To_Be_Done);
copyBody.replaceText('KeyPartsNeeded', Parts_Needed);
copyBody.replaceText('KeyPartsInStock', Parts_In_Stock);
copyBody.replaceText('KeyInvoiceNumber', Invoice_Number);
copyBody.replaceText('KeyCompletedSignature', Completed_Signature);
copyBody.replaceText('KeyIncompleteSignature', Incomplete_Signature);
copyBody.replaceText('KeyOnHoldSignature', On_Hold_Signature);
copyBody.replaceText('KeyEstimatedHours', Estimated_Hours);
copyBody.replaceText('KeyNumberOfEmployeesToComplete', Number_Of_Employees_To_Complete);
copyBody.replaceText('KeyBudget', Budget);
copyBody.replaceText('KeyFoolowUp', Follow_Up);
copyBody.replaceText('KeyOvertime', Overtime);
copyDoc.saveAndClose();
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
var doc = DocsList.getFileById(copyId);
var folders = doc.getParents();
var newFolder=DocsList.getFolder(WorkOrderForms);
doc.addToFolder(WorkOrderForms);
var docParentFolder=folders[0];
doc.removeFromFolder(docParentFolder);
}