问题
my code is meant to take an HTML form submitted in a dialog window and input it as a row in a sheet. It works perfectly for the 'Owner' (i.e. on my account) but works quite patchily for Editors (the people I share it with)-
It doesn't execute all of the code for Editors- i.e. It won't open the 2nd dialog box in the testing143() function (which is called onSuccess of the html)
It also doesn't submit properly for some users - simply hanging on the Submit button...
Is my syntax correct? I notice from this post that there may need to be extra functions ( .getClients() ?)
Here is my code - as i said, works perfectly when I was testing myself. Would be incredibly helpful for any help!
Apps Script (code runs when ShowDialog() button is pressed):
function showDialog() {
var html = HtmlService.createHtmlOutputFromFile('Index')
.setWidth(1100)
.setHeight(550);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Submit new Tellworth Idea');
}
function testing143(obj){
var ss0 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('IdeaBlotter');
var values = [[obj.date,
obj.Ticker.toUpperCase(),
obj.Analyst,
obj.Type,
obj.Idea.charAt(0).toUpperCase()+obj.Idea.slice(1),
obj.STRating,
obj.LTRating,
obj.Follow]]
ss0.insertRows(6);
var sourceRange = ss0.getRange(7,1,1,8);
var targetRange = ss0.getRange(6,1,1,8);
sourceRange.copyTo(targetRange, SpreadsheetApp.CopyPasteType.PASTE_NORMAL);
ss0.getRange(6,1,1,8).setValues(values);
var html2 = HtmlService.createHtmlOutputFromFile('Dialogue2')
.setWidth(200)
.setHeight(100);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html2, 'Submitted');
return "Thank you for your idea!";
}
And here is the JS within the HTML file (i have left out the form ofc):
<form id="myForm" onsubmit="myButton.disabled = true;testing143()">
.
.
.
<button type="submit" class="btn btn-primary btn-block" name="myButton">Submit</button>
</form>
<div id="output"></div>
</div>
</div>
</div>
<script>
function success(msg) {
alert(msg);
}
function testing143(){
var form = document.getElementById("myForm").elements;
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
if (item.checked) obj[item.name] = item.value;
else if (i < 5 || i > 14)
obj[item.name] = item.value;
}
google.script.run.withSuccessHandler(success).testing143(obj);
}
</script>
</body>
</html>
来源:https://stackoverflow.com/questions/62701249/correct-syntax-to-pass-html-form-data-to-apps-script-client-side