I wanted to insert my data to a specific sheet name based on form input value of "svdate":
<form method="get" action="submission-success.php" name="google-sheet">
<div class="form-group">Customer Name:
<input type="text" name="Customer" class="form-control" value="Michael Wilson" required readonly />
</div>
<div class="form-group">Total:
<input type="text" name="Amount" class="form-control" value="$120.00" required readonly />
</div>
<div class="form-group">Cleaner Name:
<input type="text" name="Cleaners" class="form-control" value="Dee" required readonly />
</div>
<div>
<input type="text" name="svdate" class="form-control" value="06/17/2021" required readonly hidden />
</div>
<! –– some other fields here -->
<div class="form-group">
<button type="" id="qid" class="button" onclick="this.classList.toggle('button--loading')">
<span class="button__text">Submit</span>
</button>
</div>
</form>
Here are our sheet names which are all based on dates:
Since the svdate on our form is 06/17/2021, the form data should be inserted to 6/17 sheetname. How can I do it?
Here's my script in Code.gs to insert data but I don't know how to assign the value to my sheetName variable:
var sheetName = // I want to assign the "svdate" value here...
var scriptProp = PropertiesService.getScriptProperties()
function intialSetup () {
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
scriptProp.setProperty('key', activeSpreadsheet.getId())
}
function doPost (e) {
var lock = LockService.getScriptLock()
lock.tryLock(10000)
try {
var doc = SpreadsheetApp.openById(scriptProp.getProperty('key'))
var sheet = doc.getSheetByName(sheetName)
var headers = sheet.getRange(1, 1, 1, 10).getValues()[0]
var nextRow = sheet.getLastRow() + 1
var newRow = headers.map(function(header) {
return header === 'timestamp' ? new Date() : e.parameter[header]
})
var find = sheet.getRange(1, 1, sheet.getLastRow()).createTextFinder(newRow[0]).matchEntireCell(true).findNext(); // Added
sheet.getRange(find ? find.getRow() : nextRow, 1, 1, newRow.length).setValues([newRow]); // Added
return ContentService
.createTextOutput(e.parameter.callback + "(" + JSON.stringify({ 'result': 'success', 'row': nextRow })+ ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
catch (e) {
return ContentService
.createTextOutput(e.parameter.callback + "(" + JSON.stringify({ 'result': 'error', 'error': e })+ ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT)
}
finally {
lock.releaseLock()
}
}