Google Script - DriveApp.getFilesByName - Error (No Permission) -
i'm trying call custom function pdffile google spreadsheets.
function pdffile(number, revision) { // log name of every file in user's drive. logger.log(number + '_r' + revision + '.pdf'); var files = driveapp.getfilesbyname(number + '_r' + revision + '.pdf'); while (files.hasnext()) { var file = files.next(); //var name = file.getname(); var id = file.getid(); logger.log(file.getname() + '|' + file.getid()); //return link pdf file return '=hyperlink("https://docs.google.com/file/d/'+id+'/edit?usp=drivesdk";"pdf")'; } }
it works when test in script editor manually.
function test_pdffile() { var range = spreadsheetapp.getactivespreadsheet().getsheets()[0].getrange("d2:e2"); // returns cell var number = range.getcell(1, 1).getvalue(); var revision = range.getcell(1, 2).getvalue(); result = pdffile(number, revision); logger.log(result); }
but, when use custom formula in spreadsheet, error "you don't have permission call function driveapp.getfilesbyname (row 5)" comes. have switched on drive api in resources->additional google functions , in developer console. please, find attached images (sorry, text in russian). please, help.
if custom function throws error message you not have permission call x service.
, service requires user authorization , cannot used in custom function.
check documentation more details.
hope helps!
Comments
Post a Comment