Noob here, I've been with this problem for the past week and I can't understand why the javascript will not see return values from code.gs since I have the same code but different function working as expected.
Is there a reason why the code.gs function below log values in Logger.log meaning it has data to return, but javascript won't get any values and gives me a 'null' in the alert?
Code.gs
function getInvoicesForID(studentAltID) {
var invoicesForID = [];
//get general invoices sheet and values
var sInvoices = ss.getSheetByName("Invoices");
var dataInvoices = sInvoices.getDataRange().getValues();
//get balance info for id
for(var i = 0; i < dataInvoices.length; i++){
if(dataInvoices[i][4]==studentAltID){
invoicesForID.push([dataInvoices[i][0],dataInvoices[i][1],dataInvoices[i][2],dataInvoices[i][3]]);
break;
}
}
Logger.log("invoicesForID = " + invoicesForID);
return invoicesForID;
}
javascript.html
document.getElementById("btnsearchInvPayBalforStudentID").addEventListener("click",searchInvPayBalforStudentID);
//function to look for Payments, Invoices and Balance
function searchInvPayBalforStudentID()
{
try{
//get the id
var stID = document.getElementById("txtStudentID").value;
google.script.run.withSuccessHandler(getInvoices)
.getInvoicesForID(stID);
}catch(e){
alert(e);
}
}
function getInvoices(stIDInvData) {
try{
alert(stIDInvData);
}catch(e){
alert(e);
}
}
when the code is executed and I check the logs I do see data from my gs funtion that looks like this which is the data for the expected data for the studentAltID being passed
[19-07-04 22:12:13:491 EDT] invoicesForID = Thu Jan 31 2019 00:00:00 GMT-0500 (EST),34073,Matricula 2019,298854
what am I missing?
thank you in advance :)
UPDATE:
I included the event handler (button when clicked), I checked for syntax errors and bracket mispairing but I couldn't find the problem
Here's the link to the project, which contains a few more items which I cleaned out in my posting, hopefully it might help
Thank you
}is required to be removed fromtry{ do something }}}catch(e){ do something }. I think that this might be a miswriting. I think that when there are no syntax errors,alert(stIDInvData)has the returned value fromgetInvoicesForID(stID). If the same issue occurs even when the syntax error was removed, can you provide the script for replicating your issue? Of course, please remove your personal information. - Tanaike