我正在尝试将带有标签的邮件内容(从Google工作表中读取)复制到主题为文档名称的文档中 . 如果文档已经存在,我需要在同一个文档中添加邮件正文,否则,我需要创建一个主题为doc name的doc . 我正在使用的脚本的一部分是这样的:
function searchdrive(x) {
var iterator = DriveApp.searchFiles(x);
if(iterator.hasnext()) {
var docid = iterator.next().getId();
return docid;
Logger.log(docid);
}
var doc = DocumentApp.create(x);
docid = doc.getId();
return docid;
}
如果某个doc还没有,那么iterator.hasnext()应该返回false,而是将错误作为无效参数抛出 .
我该如何解决这个问题?
2 回答
传递给_2378312的参数有一些规则_阅读本文档https://developers.google.com/apps-script/reference/drive/drive-app#searchfilesparams
Googles Apps Scripts使用Drive API的版本2,而不是v3 .
在查询字符串中替换“name”的'title' .
v2 Drive API: Search Parameters documentation