我有一个连接到谷歌表单的电子表格,我希望我们的员工能够填写并填充一个模板,将完成的模板转换为PDF文件,然后将PDF文件发送到表单中收集的电子邮件地址。直到最近,当我开始收到“例外:访问被拒绝:DriveApp”的错误消息时,表单才开始工作。我对应用程序脚本编程是新手,所以我很难追踪错误的原因,但我认为这可能是因为我将表单和相关文件移动到了我不是所有者的驱动器上。然而,我昨天把所有东西都移回了我的个人硬盘,仍然收到同样的错误。理想情况下,我希望表单能在我不是所有者的情况下使用,但我自己和其他员工都可以使用,但是我不确定如何实现这一点。

这是我的代码。我大部分时间都使用视频教程,因为我刚开始编码。错误出现在createPDF(代码:22:35)和测试(代码:13:3)。

//function createTrigger() {
//let ss = SpreadsheetApp.getActiveSpreadsheet();
//ScriptApp.newTrigger('test')
//.forSpreadsheet(ss)
//.onFormSubmit()
//.create();
//creates trigger from within spreadsheet
//}

function test(e){
const info = e.namedValues;
Logger.log (info); //Log the info for review
createPDF(info);
}

function createPDF(info){
//creates PDF from template, emails to case file and staff, and logs filename and file URL in spreadsheet

const pdfFolder=DriveApp.getFolderById("(folderID)");
const tempFolder = DriveApp.getFolderById("(folderID)"); 
const templateDoc= DriveApp.getFileById("(FileID)");
const newTempFile = templateDoc.makeCopy(tempFolder); 
const openDoc =  DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
var caseEmail = info\['Case Number'\]\[0\]+"@xxx.org";
var fileName = "HT Long Form Screening Doc: " + info\['Case Number'\]\[0\] + "-" +info\['Timestamp'\]\[0\]+ "-"+info\['Staff Name'\]\[0\];//this works
var tempFile = DriveApp.getFileById(newTempFile);
Logger.log(tempFile);
console.log(createPDF);

body.replaceText("{ts}", info\['Timestamp'\]\[0\]);
body.replaceText("{staffemail}", info\['Email'\]\[0\]);
body.replaceText("{staffname}",info\['Staff Name'\]\[0\]);
body.replaceText("{staffproject}", info\['Project'\]\[0\]);
body.replaceText("{casenumber}", info\['Case Number'\]\[0\]);
body.replaceText("{calldate}", info\['Call Date'\]\[0\]);//ok
body.replaceText("{calltime}", info\['Call Time'\]\[0\]);//ok
body.replaceText("{immediateaction}", info\['Immediate Action'\]\[0\]);//ok
body.replaceText("{immediateactiondetail}", info\['Immediate Action Detail'\]\[0\]);//ok
body.replaceText("{casemail}", caseEmail);//ok
body.replaceText("{referralsource}",info\['Referral Source'\]\[0\]);
body.replaceText("{referralsourcedetail}",info\['Referral Source Detail'\]\[0\]);
body.replaceText("{officialdetermination}",info\['Official Determination'\]\[0\]);
body.replaceText("{officialdeterminationdetail}",info\['Official Determination Detail'\]\[0\]);
body.replaceText("{personalsafety}",info\['Personal Safety'\]\[0\]);
body.replaceText("{safehousing}",info\['Safe and Stable Housing'\]\[0\]);
body.replaceText("{fairhousing}",info\['Fair Housing Referral'\]\[0\]);
body.replaceText("{survivorname}",info\['Survivor Name'\]\[0\]);
body.replaceText("{survivorphone}",info\['Survivor phone number'\]\[0\]);
body.replaceText("{survivoremail}",info\['Survivor email address'\]\[0\]);
body.replaceText("{survivoraddress}",info\['Survivor address'\]\[0\]);
body.replaceText("{survivorcounty}",info\['Survivor County of Residence'\]\[0\]);
body.replaceText("{callertype}",info\['Type of Caller'\]\[0\]);
body.replaceText("{gender}",info\['Gender'\]\[0\]);
body.replaceText("{interviewlanguage}",info\['Interview Language'\]\[0\]);
body.replaceText("{preferredlanguage}",info\['Preferred Language'\]\[0\]);
body.replaceText("{interpreter}",info\['Interpreter Needed'\]\[0\]);
body.replaceText("{callername}",info\['Caller Name'\]\[0\]);
body.replaceText("{providername}",info\['Provider Organization'\]\[0\]);
body.replaceText("{familyfriendname}",info\['Family_Friend Name'\]\[0\]);
body.replaceText("{familyfriendphone}",info\['Family_Friend Phone'\]\[0\]);
body.replaceText("{familyfriendrelationship}",info\['Family_Friend Relationship'\]\[0\]);
body.replaceText("{survivordob}",info\['Survivor DOB'\]\[0\]);
body.replaceText("{yearsofschooling}",info\['Years of Schooling'\]\[0\]);
body.replaceText("{citizenshipcountries}",info\['Citizenship Countries'\]\[0\]);
body.replaceText("{birthcountry}",info\['Birth Country'\]\[0\]);
body.replaceText("{whyleftcountry}",info\['Why Left Country'\]\[0\]);
body.replaceText("{threemonthscountry}",info\['3 Months Country'\]\[0\]);
body.replaceText("{recentarrival}",info\['Recent Arrival'\]\[0\]);
body.replaceText("{arrangetravel}",info\['Arrange Travel?'\]\[0\]);
body.replaceText("{whoarrangedtravel}",info\['Who Arranged Travel'\]\[0\]);
body.replaceText("{arrangetraveldetail}",info\['Arranged Travel Detail'\]\[0\]);
body.replaceText("{pressuredyou}",info\['Pressured You'\]\[0\]);
body.replaceText("{pressuredyoudetail}",info\['Pressured You Detail'\]\[0\]);
body.replaceText("{totalcost}",info\['Total Cost'\]\[0\]);
body.replaceText("{borrowmoney}",info\['Borrow Money'\]\[0\]);
body.replaceText("{existingdebt}",info\['Existing Debt'\]\[0\]);
body.replaceText("{existingdebtdetail}",info\['Existing Debt Detail'\]\[0\]);
body.replaceText("{pressuredtopay}",info\['Pressured to Pay'\]\[0\]);
body.replaceText("{pressuredtopaydetail1}",info\['Pressured to Pay Detail 1'\]\[0\]);
body.replaceText("{pressuredtopaydetail2}",info\['Pressured to Pay Detail 2'\]\[0\]);
body.replaceText("{supposedtobepaidforwork}",info\['Supposed to be paid for work'\]\[0\]);
body.replaceText("{kindofwork}",info\['Kind of Work'\]\[0\]);
body.replaceText("{foundoutaboutwork}",info\['How found out about work'\]\[0\]);
body.replaceText("{didnotgetpaid}",info\['Not Paid'\]\[0\]);
body.replaceText("{kindofwork2}",info\['Kind of work 2'\]\[0\]);
body.replaceText("{kindofwork3}",info\['Kind of work 3'\]\[0\]);
body.replaceText("{paymentexpected}",info\['Payment expected'\]\[0\]);
body.replaceText("{paymentreceived}",info\['Payment received'\]\[0\]);
body.replaceText("{hownotpaid}",info\['How not paid'\]\[0\]);
body.replaceText("{differentwork}",info\['Different work than expected'\]\[0\]);
body.replaceText("{workpromised}",info\['What were you promised'\]\[0\]);
body.replaceText("{actualwork}",info\['What actual work'\]\[0\]);
body.replaceText("{workfeelscared}",info\['Work feel scared'\]\[0\]);
body.replaceText("{workfeelscareddetail}",info\['Work feel scared detail'\]\[0\]);
body.replaceText("{workhurt}",info\['Work hurt'\]\[0\]);
body.replaceText("{workhurtdetail}",info\['Work hurt detail'\]\[0\]);
body.replaceText("{workthreats}",info\['Work threats'\]\[0\]);
body.replaceText("{workthreatsdetail}",info\['Work threats detail'\]\[0\]);
body.replaceText("{tworktakebreaks}",info\['Work take breaks'\]\[0\]);
body.replaceText("{worksickoremergency}",info\['Work sick or emergency'\]\[0\]);
body.replaceText("{worktakebreaksdetail}",info\['Work take breaks detail'\]\[0\]);
body.replaceText("{askpermission}",info\['Have to ask permission'\]\[0\]);
body.replaceText("{nopermission}",info\['What if no permission'\]\[0\]);
body.replaceText("{workinjured}",info\['Work injured'\]\[0\]);
body.replaceText("{workinjurednomedical}",info\['Work injured stopped from medical'\]\[0\]);
body.replaceText("{workinjurednomedicaldetail}",info\['Work injured stopped from medical detail'\]\[0\]);
body.replaceText("{workpressured}",info\['Work pressured'\]\[0\]);
body.replaceText("{workpressureddetail}",info\['Work pressured detail'\]\[0\]);
body.replaceText("{workphotos}",info\['Work photos'\]\[0\]);
body.replaceText("{workphotoswho}",info\['Work photos who'\]\[0\]);
body.replaceText("{workphotoswhatplanned}",info\['Work photos plan to do'\]\[0\]);
body.replaceText("{workphotosagreement}",info\['Work photos agreement'\]\[0\]);
body.replaceText("{worksexforvalue}",info\['Work sex for value'\]\[0\]);
body.replaceText("{worksexforvaluepressured}",info\['Work sex for value pressured'\]\[0\]);
body.replaceText("{worsexforvalueage}",info\['Work sex for value age'\]\[0\]);
body.replaceText("{worktakeid}",info\['Work take ID'\]\[0\]);
body.replaceText("{worktakeidgetback}",info\['Work take ID could retrieve'\]\[0\]);
body.replaceText("{worktakeidwhathappened}",info\['Work take ID what happened'\]\[0\]);
body.replaceText("{worktakemoney}",info\['Work take money'\]\[0\]);
body.replaceText("{worktakemoneyagreed}",info\['Work take money agreed'\]\[0\]);
body.replaceText("{worktakemoneydetail}",info\['Work take money detail'\]\[0\]);
body.replaceText("{whereliving}",info\['Where living'\]\[0\]);
body.replaceText("{livesameplacework}",info\['Live same place work'\]\[0\]);
body.replaceText("{livesameplaceworkdetail}",info\['Live same place work detail'\]\[0\]);
body.replaceText("{workcouldnotleave}",info\['Work felt could not leave'\]\[0\]);
body.replaceText("{workcouldnotleavedetail}",info\['Work felt could not leave detail'\]\[0\]);
body.replaceText("{worktriedtoleave}",info\['Work what if tried to leave'\]\[0\]);
body.replaceText("{worklockedin}",info\['Work locked in'\]\[0\]);
body.replaceText("{worklockedindetail}",info\['Work locked in detail'\]\[0\]);
body.replaceText("{workmonitored}",info\['Work monitored'\]\[0\]);
body.replaceText("{workmonitoreddetail}",info\['Work monitored detail'\]\[0\]);
body.replaceText("{workoutsidecontact}",info\['Work outside contact'\]\[0\]);
body.replaceText("{workfalseid}",info\['Work false ID'\]\[0\]);
body.replaceText("{workfalseiddetail}",info\['Work false ID detail'\]\[0\]);
body.replaceText("{workreporttocops}",info\['Work report to cops'\]\[0\]);
body.replaceText("{workreporttocopsdetail}",info\['Work report to cops detail'\]\[0\]);
body.replaceText("{workothersthreatened}",info\['Work others threatened'\]\[0\]);
body.replaceText("{workothersthreateneddetail}",info\['Work others threatened detail'\]\[0\]);
body.replaceText("{workfoodcontrol}",info\['Work food control'\]\[0\]);
body.replaceText("{workfoodcontroldetail}",info\['Work food control detail'\]\[0\]);
body.replaceText("{worksleepcontrol}",info\['Work sleep control'\]\[0\]);
body.replaceText("{worksleepcontroldetail}",info\['Work sleep control detail'\]\[0\]);
body.replaceText("{worklanguage}",info\['Work language difficulties'\]\[0\]);
body.replaceText("{indicators}",info\['Victimization indicators'\]\[0\]);
body.replaceText("{inaccurate}",info\['Inaccurate responses'\]\[0\]);
body.replaceText("{likelihood}",info\['Likelihood'\]\[0\]);
body.replaceText("{ratingreason}",info\['Rating reason'\]\[0\]);
body.replaceText("{referralstomake}",info\['Referrals to be made'\]\[0\]);
body.replaceText("{notes}",info\['Additional notes'\]\[0\]);

openDoc.saveAndClose();//works but should it delete the temp file now?

const blobPDF=newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName(fileName);
//tempFolder.removeFile(tempFile);//not sure that this works
var newFileID = pdfFile.getId();

var subject = 'Screening Note to File';
var emailBody = info\['Case Number'\]\[0\] + " " + info\['Staff Name'\]\[0\];
var caseEmail = info\['Case Number'\]\[0\]+"@xxx.org";//this works
var fileName = info\['Case Number'\]\[0\] + " " +info\['Timestamp'\]\[0\];
var staffemail = info\['Email'\]\[0\];
Logger.log(caseEmail);
Logger.log(fileName);

DriveApp.getFileById(newFileID);
GmailApp.sendEmail(caseEmail, subject, emailBody,{attachments:pdfFile});
GmailApp.sendEmail(staffemail, subject, emailBody, {attachments:pdfFile});

var htFileURL = pdfFile.getUrl();
Logger.log(htFileURL);

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet1 = sheets\[0\];
var cell = sheet1.getActiveCell();
var selectRow = cell.getRow();
Logger.log ("SelectRow: " + selectRow);

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1").getRange(selectRow,120).setValue(htFileURL);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1").getRange(selectRow, 121).setValue(fileName);

}

应用程序脚本错误-访问被拒绝:DriveApp的更多相关文章

  1. 在Squarespace网站中使用AWS Cognito和Stripe集成添加Google登录

    我已经为后端的API调用设置了无服务器Lambda函数,以及API网关,以保护对该函数的未授权访问。下一步是实施条带集成。我的网站是在Squarespace中建立的。我希望用户使用CognitoGoogle登录,然后订阅一个定期付款计划。我已经查看了Spacesquare内的商业选项卡,该选项卡可以选择连接条带,但存在一些问题。我在Stripe中创建的产品未同步用户应该首先通过Cognito登录,据我所知,似乎没有合适的插件来解决这个问题如果我使用自己的自定义登录。squarespace将如何跟踪有关订阅

  2. A列而非B列中的项目计数(Google表单)

    我在谷歌表上有两列数字。我正在试图找到一个公式来计算a列中不在B列中的项目数。列中的数字是递减的,并且在每列中都是唯一的,但可以在列之间重复。列中也可以包含不同数量的项目。AB5442311答案是这种情况下是2,因为A列中的数字5和3不在B列中。我尝试过使用sum、if和countif,但无法找到解决方案。也不确定这是否是一个数组公式。

  3. 如何从Google Apps脚本中的文件列表创建快捷方式?

    由于机构存档政策,我现在失去了对TIFImages的读取权限,但获得了对JPGImages的访问权限,其中包含所有相同图像的较低分辨率.jpg副本。为了避免再次手动组织所有图像,我想使用GoogleDrive脚本查看每个文件夹的快捷方式,并使用新的.jpg图像重新创建快捷方式。我想我已经找到了获取.tif图像的所有.jpg版本的第一部分,但实际上我很难创建快捷方式。这是我第一次使用Google脚本或Javascript,所以我确信这段代码是丑陋和错误的。如有任何帮助,将不胜感激。

  4. 如何使用Google App脚本开发SUMIFS(表格)

    我正在尝试使用Google应用程序脚本在Google表单中执行SUMIFS。我有这个表原始表我需要创建这个结构:最终表格考虑ID和类似月份的条件来对任务求和。使用查询进行了多次尝试,但效果不佳,因为有些任务没有值(空)谢谢你的帮助!

  5. 使用GoogleSheet AppScript更新Firestore文档

    我发现很难更新消防商店集合中的字段。人员的文档ID是自动生成的。下面的内联代码显示了我能够从我所学的教程中获得的内容和取得的成果。除了“updateFirestoreDocument”函数,其他所有函数都可以正常工作。如何重写代码以将GoogleSheets上的修改单元格导出到firestore集合中的正确人员字段?谢谢我尝试定义documentId我希望documented被重命名文档字段被错误修改

  6. 一个单元格中不同字体颜色的Excel公式

    您能否提供一个公式,在Excel中将单个单元格值显示为具有多种颜色的文本,其中一半文本为红色,其余文本为蓝色,因为该值在单个单元格中给出,需要在同一单元格中以两种颜色显示。请在此处输入图像描述公式:输出ERRORS&WARNINGS在此处输入图像描述

  7. 谷歌登录iframe在两个类似的页面上呈现不同

    后端运行良好,但当页面加载时,生成的iframe结构在以下环境中看起来不同:环境1:环境2:正如您所看到的,Environment2iframe有一个div填充了另一个东西,而另一个div是空的。对于环境2,屏幕上的结果如下所示:Google按钮正在覆盖其他两个按钮,并复制其中的标签。以前有人遇到过这个问题吗?实现这一点的代码如下:

  8. 应用程序脚本错误-访问被拒绝:DriveApp

    我有一个连接到谷歌表单的电子表格,我希望我们的员工能够填写并填充一个模板,将完成的模板转换为PDF文件,然后将PDF文件发送到表单中收集的电子邮件地址。直到最近,当我开始收到“例外:访问被拒绝:DriveApp”的错误消息时,表单才开始工作。我对应用程序脚本编程是新手,所以我很难追踪错误的原因,但我认为这可能是因为我将表单和相关文件移动到了我不是所有者的驱动器上。错误出现在createPDF和测试。

随机推荐

  1. 如何扩展ATmega324PB微控制器的以下宏寄存器?

    我目前正在学习嵌入式,我有以下练习:展开以下宏寄存器:如果有人解决了这个问题,我将不胜感激,以便将来参考

  2. Python将ONNX运行时设置为返回张量而不是numpy数组

    在python中,我正在加载预定义的模型:然后我加载一些数据并运行它:到目前为止,它仍在正常工作,但我希望它默认返回Tensor列表,而不是numpy数组。我对ONNX和PyTorch都是新手,我觉得这是我在这里缺少的基本内容。这将使转换中的一些开销相同。

  3. 在macOS上的终端中使用Shell查找文件中的单词

    我有一个文本文件,其中有一行:我需要找到ID并将其提取到变量中。我想出了一个RexEx模式:但它似乎对我尝试过的任何东西都不起作用:grep、sed——不管怎样。我的一个尝试是:我为这样一个看似愚蠢的问题感到抱歉,但我在互联网上找不到任何东西:我在SO和SE上读了几十个类似的问题,并在谷歌上搜索了几个教程,但仍然无法找到答案。欢迎提供任何指导!

  4. react-chartjs-2甜甜圈图中只有标题未更新

    我正在使用react-chartjs-2在我的网站中实现甜甜圈图。下面是我用来呈现图表的代码。我将甜甜圈图的详细信息从父组件传递到子组件,所有道具都正确传递。当我在beforeDraw函数外部记录props.title时,它会记录正确的值,但当我在beforeDraw函数内部记录props.title时,它将记录标题的前一个值,从而呈现标题的前值。我在这里做错了什么?

  5. 如何在tkinter中使用Python生成器函数?

    生成器函数承诺使某些代码更易于编写。但我并不总是知道如何使用它们。假设我有一个斐波那契生成器函数fib(),我想要一个显示第一个结果的tkinter应用程序。当我点击“下一步”按钮时,它会显示第二个数字,依此类推。我如何构建应用程序来实现这一点?我可能需要在线程中运行生成器。但如何将其连接回GUI?

  6. 如何为每次提交将存储库历史记录拆分为一行?

    我正在尝试获取存储库的历史记录,但结果仅以单行文本的形式返回给我。

  7. 尝试在颤振项目上初始化Firebase时出错

    当尝试在我的颤振项目上初始化firebase时,我收到了这个错误有人知道我能做什么吗?应用程序分级Gradle插件Gradle项目颤振相关性我已经将firebase设置为Google文档已经在另一个模拟器上尝试过,已经尝试过创建一个全新的模拟器,已经在不同的设备上尝试过了,已经尝试了特定版本的firebase,已经尝试添加但没有任何效果,已经在youtube上看到了关于它的每一个视频,该应用程序在android和iOS两个平台上都抛出了这个错误

  8. 在unix中基于当前日期添加新列

    我试图在unix中基于时间戳列在最后一个单元格中添加一个状态列。我不确定如何继续。

  9. 麦克斯·蒙特利。我一直得到UncaughtReferenceError:当我在终端中写入node-v时,节点未定义

    如果这是您应该知道的,请确认:我已将所有shell更改为默认为zsh。当我在终端中写入node-v时,我一直收到“UncaughtReferenceError:nodeisnotdefined”。但它显示节点已安装。我是个新手,在这方面经验不足。

  10. 如何在前端单击按钮时调用后端中的函数?

    那么如何在后端添加一个新的端点,点击按钮调用这个函数。

返回
顶部