Home > Software engineering >  Get File by name in docs.google
Get File by name in docs.google

Time:05-05

What am I doing wrong? I want to get a link to google drive from the file name in the cell

function main (file){
  return DriveApp.getFilesByName(file).next().getUrl();
}

But I get a "name" error. I don't even have such a variable

Exception: Invalid argument: name

main @ test.gs:2

CodePudding user response:

I think you're trying to run the function main() directly via the 'Run' button in Script Editor. This way the function gets no arguments. You have to call the main() function from another function.

Something like this:

// this is the function to run via Run button
function myFunction() {
  var url = main('test file');
  console.log(url);
}

function main(file) {
  return DriveApp.getFilesByName(file).next().getUrl();
}

enter image description here

  • Related