Shared Google Sheet (Editor Access for Collaborator), with Custom UI TemplateHtml, serves html, but does not append row. Works for Sheet Owner
I have a working (working for me, the owner of the sheet/ app script) apps script that allows a user to enter any customer interaction. The user is a collaborator on the Sheet, with Editor access.
When the collaborator runs the custom menu item, a html is served (Template), but when the collaborator hits Submit, the data does not get appended to the specified tab on the spreadsheet. This works fine if I run it, though.
Reading a bit of the documentation seems to suggest an Authmode issue? Any pointers gratefully appreciated. Thanks.
Here is my CODE.GS
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.createMenu('Customer Engagement')
.addItem('Record Interaction', 'showDialog')
.addToUi();
}
function showDialog() {
var html = HtmlService.createTemplateFromFile('RecordInteraction.html');
html.data = readData();
SpreadsheetApp.getUi().showModalDialog(html.evaluate().setWidth(400).setHeight(600), 'Please Enter Details');
}
function readData() {
var url = "https://docs.google.com/spreadsheets/d/13Ms0Cny3f-XaXS26s5AnrDT4H9c8p8OKRfwxPIQ9_CU/edit#gid=16760772";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Pipeline");
var rng = ws.getRange('D2:D')
var rangeArray = rng.getValues();
var filArray = rangeArray.filter(function (el) {return el[0] != ""}).flat(); // Modified
console.info("hello read the data")
return filArray;
}
function activateSheetById(sheetId) {
//Access all the sheets in the Google Sheets spreadsheet
var sheets = SpreadsheetApp.getActive().getSheets();
//Filter out sheets whose Ids do not match
var sheetsForId = sheets.filter(function(sheet) {
return sheet.getSheetId() === sheetId;
});
//If a sheet with the Id was found, activate it
if(sheetsForId.length > 0)
sheetsForId[0].activate();
}
function appendRowFromFormSubmit(form) {
var row = [form.name, form.doi, form.mode, form.feedback, form.temperature];
console.info("Appending Row");
activateSheetById(2059810756);
SpreadsheetApp.getActiveSheet().appendRow(row);
}
function RemoveMenu() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.removeMenu('Customer Contact');
}
Here is my HTML+JS
<!DOCTYPE html>
<html>
<head>
<style>
label {
display: inline-block;
width: 150px;
}
</style>
<base target="_top">
<script>
function submitForm() {
google.script.run.appendRowFromFormSubmit(document.getElementById("feedbackForm"));
document.getElementById("form").style.display = "none";
document.getElementById("thanks").style.display = "block";
}
</script>
</head>
<body>
<datalist id="datalist">
<?
data.forEach(e => {
?>
<option value="<?= e ?>">
<? }); ?>
</datalist>
<div>
<div id="form">
<h1>Record Interaction</h1>
<form id="feedbackForm">
<label for="name">Parent Name</label>
<input type="text" id="name" name="name" list="datalist"><br><br>
<label for="doi">Date of Interaction</label>
<input id="today" type="date" name="doi"><br><br>
<label for="mode">Mode of Interaction (WA/Call/Email/Other)</label>
<input type="text" id="mode" name="mode"><br><br>
<label for="feedback">Interaction Summary</label>
<textarea rows=4 cols=35 id="feedback" name="feedback">Enter Interaction Summary Here...
</textarea><br><br>
<div>
<label for="temperature">Likely Candidate?</label><br>
<input type="radio" id="Hot" name="temperature" value="Hot">
<label for="yes">Hot</label><br>
<input type="radio" id="Warm" name="temperature" value="Warm">
<label for="yes">Warm</label><br>
<input type="radio" id="Tepid" name="temperature" value="Tepid">
<label for="yes">Tepid</label><br>
<input type="radio" id="Cold" name="temperature" value="Cold">
<label for="no">Cold</label><br><br>
<input type="button" value="Submit Interaction" onclick="submitForm();">
</form>
</div>
</div>
<div id="thanks" style="display: none;">
<p>Thank you for speaking to our customers!</p>
</div>
</body>
</html>
Solution 1:
Problem resolved!!! It was a matter of being logged into Google on 2 different accounts. Use a private browsing window, and there's no problem!