Reputation: 53
I'm trying to copy mail content with a label (read from a google sheet) into a document with the subject as the doc name. If a doc already exists, I need to add mail body in the same doc, if not, I need to create a doc with the subject as doc name. part of the script that I'm using is this:
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;
}
If a doc is not already there, iterator.hasnext() should be returning false but instead it's throwing an error as invalid argument.
How do I work around with this?
Upvotes: 4
Views: 2857
Reputation: 824
Googles Apps Scripts utilizes version2 of the Drive API, not v3.
Substitute 'title' for 'name' in your query string.
v2 Drive API: Search Parameters documentation
Upvotes: 4
Reputation: 2612
There are some rules for an argument passed to DriveApp.searchFiles(params)
read this documentation https://developers.google.com/apps-script/reference/drive/drive-app#searchfilesparams
Upvotes: 1