javascript - createFile() in google Apps Script is not functioning properly -



javascript - createFile() in google Apps Script is not functioning properly -

i trying create file. works fine when run next code segment debugger in apps script. however, when run real time spreadsheet, says not have permission phone call createfile. logged identical. issue not not have authorization 1 in spreadsheet , owner. purpose of csv move google drive info bigquery

function saveascsv(row) { //doc csv //row = 3; //when uncommented , ran debugger, works. try{ var filename= date.now() filename = filename + ".csv"; var csvfile = convertrangetocsvfile_(filename,row); logger.log(csvfile); //both times ran on spreadsheet , debug equals same. driveapp.createfile(filename, csvfile); spreadsheetapp.getactivespreadsheet().getsheetbyname("new , open").getrange("j" + row.tostring()).setvalue(""); loadcsv(filename); } catch(e){logger.log("b" + e.message);} //no permission create file } function convertrangetocsvfile_(csvfilename, r) { var ws = spreadsheetapp.getactivespreadsheet(); seek { //var info = ws.getvalues(); var csvfile = undefined; var csv = ""; var row = r; var datarray = create2darray(1,19); datarray[0][0] = ws.getrange("a" + row.tostring()).getvalue().tostring().touppercase(); datarray[0][1] = ws.getrange("b"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][2] = ws.getrange("c"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][3] = ws.getrange("d"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][4] = ws.getrange("e"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][5] = ws.getrange("f"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][6] = ws.getrange("g"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][7] = ws.getrange("h"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][8] = ws.getrange("i"+row.tostring()).getvalue().tostring().touppercase(); datarray[0][9] = new date(ws.getrange("k"+row.tostring()).getvalue().tostring()).gethours(); datarray[0][10] = new date(ws.getrange("k"+row.tostring()).getvalue().tostring()).getminutes(); datarray[0][11] = new date(ws.getrange("l"+row.tostring()).getvalue().tostring()).gethours(); datarray[0][12] = new date(ws.getrange("l"+row.tostring()).getvalue().tostring()).getminutes(); datarray[0][13] = new date(ws.getrange("m"+row.tostring()).getvalue().tostring()).gethours(); datarray[0][14] = new date(ws.getrange("m"+row.tostring()).getvalue().tostring()).getminutes(); datarray[0][15] = new date(ws.getrange("n"+row.tostring()).getvalue().tostring()).gettime(); datarray[0][16] = new date(ws.getrange("n"+row.tostring()).getvalue().tostring()).getfullyear(); datarray[0][17] = new date(ws.getrange("n"+row.tostring()).getvalue().tostring()).getmonth(); datarray[0][18] = new date(ws.getrange("n"+row.tostring()).getvalue().tostring()).getdate(); for(var = 0; < 19; i++){ if(datarray[0][i] == ""){if(i > 9){datarray[0][i] = 0;} else{datarray[0][i] = "nil";} } if(i < 18){csv += '"' + datarray[0][i] + '"' + ",";} else{ csv += '"' + datarray[0][i] + '"'; } } logger.log("a " + csv); logger.log(csv + "\n" + datarray[0].join(",")); csvfile = csv; homecoming csvfile; } catch(err) { logger.log("c" + err); browser.msgbox(err); } }

you mention in comment on reply using onedit trigger script. since simple trigger, current approach not work. when utilize simple triggers run apps script, runs in sandbox reduced permissions.

see: https://developers.google.com/apps-script/guides/triggers/#restrictions

the best can recommend create custom menu alternative ui popup asking row number export. if code triggered menu user, runs total permission access users account.

depending on use-case, scheduled trigger might work too. run every 10 minutes or every hr , export changes spreadsheet. in case apps script runs you, permission access account, , resulting csv created on drive.

details on how create custom menu: https://developers.google.com/apps-script/guides/triggers/#onopen

details on how create form user: https://developers.google.com/apps-script/guides/ui-service

details on time driven triggers: https://developers.google.com/apps-script/guides/triggers/installable#time-driven_triggers

javascript csv google-apps-script google-bigquery

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -