I had google script apps working fine for several months and it suddenly stopped working. I am wondering if Google has rejected some part of my code or something like that.
This is a link to a file: Click here to view a Google Spreadsheet file.
The google script code does not seem to work when trying to call the google script function from an HTML file. This is a line of code that fails.
google.script.run.importCSVData(id);
Lines fail and detect the following error:
TypeError: Cannot read the 'run' property from undefined
As I said, this code worked fine for me for several months, and it suddenly stopped working.
(FYI ... The purpose of this code is to upload the CSV file to the “Archivo Plano ADN” tab. To run this code, simply select “Importar Archivo CSV” → “Importar Archivo .." .. "from the top menu. When prompted to select file, select any CSV file. The csv file must be split :)
There are three code files in my Google Spreadsheet file ("Code.gs", "CodeImport.gs" and "Picker.html")
Let me give you the code for each of them:
Code.gs:
function onOpen() { var me = Session.getEffectiveUser(); if (me.getEmail() == " alejandro.sardi@crusardi.net ") { var ui = SpreadsheetApp.getUi(); ui.createMenu('Protected Ranges') .addItem('Remove Protection', 'menuItem1') .addItem('Copy Protected Ranges To Another Sheet', 'menuItem2') .addItem('Copy SM Protected Ranges to all SA sheets', 'menuItem3') .addToUi(); ui.createMenu('Importar Archivo CSV') .addItem('Importar Archivo...', 'showPicker') .addToUi(); ui.cre } else { SpreadsheetApp.getUi()
CodeImport.gs:
function importCSVData(id) { try { var file = DriveApp.getFileById(id); var csvData = Utilities.parseCsv(file.getBlob().getDataAsString("ISO-8859-1"),";"); var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Archivo Plano ADN"); sheet.getRange("A:U").clear(); sheet.getRange("G:G").setNumberFormat('@ STRING@ '); Logger.log("yes"); sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData); file.setTrashed(true); SpreadsheetApp.getUi().alert("Archivo Importado con éxito"); } catch (e) { MailApp.sendEmail(Session.getEffectiveUser().getEmail(), "Error report jaja - sonríele a la vida!", "\r\nMessage: " + e.message + "\r\nFile: " + e.fileName + "\r\nLine: " + e.lineNumber); } } function showPicker() { var html = HtmlService.createHtmlOutputFromFile('Picker.html') .setWidth(600) .setHeight(425) .setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi().showModalDialog(html, 'Select File'); } function getOAuthToken() { DriveApp.getRootFolder(); return ScriptApp.getOAuthToken(); } function finishedImport() { SpreadsheetApp.getUi().alert("Archivo importado exitosamente"); } function senderror(e) { MailApp.sendEmail(Session.getEffectiveUser().getEmail(), "Error report jaja - sonríele a la vida!", "\r\nMessage: " + e.message + "\r\nFile: " + e.fileName + "\r\nLine: " + e.lineNumber); }
And finally, the Picker.html file:
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css"> <script type="text/javascript"> var DIALOG_DIMENSIONS = { width: 600, height: 425 }; var pickerApiLoaded = false; function onApiLoad() { gapi.load('picker', { 'callback': function() { pickerApiLoaded = true; } }); google.script.run.withSuccessHandler(createPicker) .withFailureHandler(showError).getOAuthToken(); } function createPicker(token) { if (pickerApiLoaded && token) { </script> </head> <body> <div> <p id='result'></p> </div> <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script> </body> </html>