UI to HTML, conversion will not write a date to th

2019-08-15 22:37发布

I am trying to replicate a question posed by Pieter Jaspers regarding a conversion of a form from UIApp to HTML. The original question is:

Original question by Pieter Jaspars answered by Sandy Good

If I replicate the code exactly I get the correct result, but when I try to recreate my inline form and amalgamate the two I am not getting a result. The inline form question is here:

HTML inline form formatting question answered by Mogsdad

The code I have so far is in the requisite number of parts, a form and two .gs sheets. I have checked for spelling mistakes and I have tried editing out each line to see what and where I get, but with my limited experience I am drawing a blank. The only minor success is if I run the function InsertInSS() from within the code editor. This posts the word "undefined" in the correct cell in the correct spreadsheet, but not the date as I am trying to do!

Form:

<!-- Use a templated HTML printing scriptlet to import common stylesheet. -->
<?!= HtmlService.createHtmlOutputFromFile('Stylesheet').getContent(); ?>
<html>
  <body>
  <div>
  <!-- Page header title & 'completion warning -->
  <span class="grey"><b>ProReactive Log Form v3.0.74</b></span>
  <h4>Complete ALL fields to ensure the form is processed successfully</h4>
  <div class="block">
  <!-- First input box created -->
  <div class="inline form-group">
  <label form="date">Date</label>
  <input type="date" id="date" style="width: 125px;">
  </div>
  </div>
  </div>
  <!-- End of fields for completion, finish form with submission button -->
  <button class="share" onclick="runGoogleScript()">submit</button>
  </body>
  </html>

  <script>
  function onSuccess(argReturnValue){
      alert('was successful ' +argReturnValue);
      //ResetFields on Screen
      Document.getElementById("date").value = "";
      }

  function runGoogleScript() {
      logger.log('v3.0.74 ran!');
      var inputValue = document.getElementById("date").value;
      google.script.run.withSuccessHandler(onSuccess)
      .InsertInSS(inputValue);
      };

  </script>

The Code.gs:

function doGet(e) {

  return HtmlService.createTemplateFromFile('myForm')
  .evaluate()
  .setTitle('ProReactiveLog')
  .setSandboxMode(HtmlService.SandboxMode.NATIVE);
};

and the seperate.gs:

function InsertInSS(argPassedInName) {
  var ssKey = '1cZuEMDrIyzIFm4lGCT20s-Wpv27o0hbbZAsxD1WJFL8';

  var SS = SpreadsheetApp.openById(ssKey);
  var Sheet = SS.getSheetByName('LOG');
  Sheet.getRange(Sheet.getLastRow()+1,1,1).setValue(argPassedInName);

}

Any ideas where I am going wrong? All help as ever, greatly appreciated.

1条回答
叼着烟拽天下
2楼-- · 2019-08-15 22:52

An Apps script HTML App, will not allow a date object to be passed to the server.

google.script.run Parameter Documentation

The documentation states:

Requests fail if you attempt to pass a Date, Function, DOM element besides a form, or other prohibited type, including prohibited types inside objects or arrays.

You will need to pass the date as a string. Convert the date to a string in client side code, and convert it back to a date, if need be, in the server code. However, even if you set the value in the spreadsheet as a string, it may get coerced back into a date without you needing to do anything. Especially if you have that column defined as a date in the spreadsheet.

查看更多
登录 后发表回答