I'm not a good programmer or English speaker, sorry.
I try to access a Google spreadsheet with app script and from fixer .gs I can get the record I want but at the same time switching it to javascript the console returns "null".
This only happens when there are special characters in the fields I'm looking for, such as colon.
function recullEntrades(){
const ss = SpreadsheetApp.openByUrl(url);
const ws = ss.getSheetByName("Dades");
Logger.log(ws.getRange(2,1, ws.getLastRow()-1,7).getDisplayValues())
return ws.getRange(2,1, ws.getLastRow()-1,7).getValues();
}
This is ok in the Logger but then,
function miraEntrades(entrades) {
console.log("entrades: " + entrades);
}
$('#vomita').click(function(){
google.script.run.withSuccessHandler(miraEntrades).recullEntrades();
})
In the chrome console i get "null", this is not happening if i not use colon.
Thanks.
Like pointed above by @Josep, it looks like you're logging the values using getDisplayValues but you're returning the values using getValues.
According to the Apps Script documentation:
getDisplayValuesReturns a two-dimensional array of displayed values, indexed by row, then by column. The values are String objects. The displayed value takes into account date, time and currency formatting, including formats applied automatically by the spreadsheet's locale setting. Empty cells are represented by an empty string in the array.
getValuesReturns a two-dimensional array of values, indexed by row, then by column. The values may be of type Number, Boolean, Date, or String, depending on the value of the cell. Empty cells are represented by an empty string in the array.
Therefore, depending on the exact use-case, you might benefit from returning the values using the getDisplayValues method instead.