Home > OS >  getFileById() with dynamic ID
getFileById() with dynamic ID

Time:11-26

This line of code uses the id entered manually in the script

let copyFile =DriveApp.getFileById('1GhpGpHM......').makeCopy(),                    
copyID = copyFile.getId(),                    
copyDoc = DocumentApp.openById(copyID),

How could I use the ID that can be found manually written in the google spreadsheet, so that if I change it from the spreadsheet, it will also change automatically in the script. I have a list of IDs associated with some templates.

Can something be done about this?

I used :

var ID_template = ss.getRangeByName('ID_template').getValue;

and then

let copyFile = DriveApp.getFileById(ID_template).makeCopy(),
copyID = copyFile.getId(),
copyDoc = DocumentApp.openById(copyID),

but without any result.

CodePudding user response:

Yes, it is possible. Probably your issue is that you're missing brackets () after .getValue()

  • Related