OblongMedulla
OblongMedulla

Reputation: 1595

Google scripts app- variable within variable error

Google drive script for searching- I can't add the variable for searchterm. As soon as I add it I continue to get errors - Perhaps I am going about it wrong?

Ultimately I would like a web app with a searchbox, button that searches for the terms. With the owneris variable...

function SearchFiles() {
//Please enter your search term in the place of Letter
var searchterm ='print';
var searchFor ='title contains "searchterm"';
var owneris ='and "[email protected]" in Owners';
var names =[];
var fileIds=[];
var files = DriveApp.searchFiles(searchFor + owneris);
while (files.hasNext()) {
  var file = files.next();
  var fileId = file.getId();// To get FileId of the file
 fileIds.push(fileId);
 var name = file.getName();
 names.push(name);

}

for (var i=0;i<names.length;i++){
 Logger.log(names[i]);
Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);

}

}

Upvotes: 0

Views: 62

Answers (1)

utphx
utphx

Reputation: 1285

You just need to add quotes in the right places and it should work:

var searchterm ="'print';
var searchFor ="title contains " + searchterm;
var owneris =" and '[email protected]' in owners";

Be sure to change [email protected]

Upvotes: 2

Related Questions