0
votes

The same function works fine, if the code is not imported and just in the sheet.

The .withSuccessHandler() don't pass on the return value to the called function.

The code in code.gs returns a Boolean (the log gets it), the function called with .withSuccessHandler() doesn't get it and the variable is undefined.

html

<html>
  <form id="myForm">
  [...]
  <input type="button" value="Submit" 
 onClick="google.script.run.withSuccessHandler(DataSaved).withFailureHandler(Error).processForm(this.form)"
        />
</form>
<div id="Message"></div>
 <script>
    function DataSaved(ret){
    if(ret==true){
    document.getElementById('Message').innerHTML = "Finished!";
    }else{
    document.getElementById('Message').innerHTML = ret+"Wrong Sheet!";
    }
};
    function Error(err){
    document.getElementById('Message').innerHTML = "An error occurred: "+err;
};
 </script>

code.gs

function processForm(myForm) {
  var data = myForm.data
  var fu = ParseExport(data)
  console.log(typeof fu);console.log(JSON.stringify(fu))
  return fu
}

The resulting line is: undefinedWrong Sheet!

Stackdriver

Stackdriver-Protokolle
29.06.2019, 19:39:11
FEHLERBEHEBUNG
boolean
29.06.2019, 19:39:11
FEHLERBEHEBUNG
true

I don't know where to look for the mistake anymore. Even moved the google.script.run function in the script block to test if it changes anything (it don't). The error handler works fine...

1
Try console.log(typeof fu);console.log(JSON.stringify(fu)). Provide ParseExport return type/value - TheMaster
added the extended logging (see above). - Tezexlo
Is ret defined somewhere else? Can you try moving the script block above the form block? - TheMaster
Also, try just returning true function processForm(myForm) {return true} - TheMaster
moving the script block didn't help and ret and err are the only variables in the html. Renamed it anyway to be sure, but didn't change anything. - Tezexlo

1 Answers

0
votes

It was my mistake, as the importing Sheet has a wrapper class to handle the the call to the imported script functions, which needs to pass the return along, too.