Hey I am trying to add more values (from a submit form) to a specified existing row. But I got Console error:
Uncaught at processPk1
Here's my .html code:
onsubmit="handleFormSubmit(this) //got this onsubmit in my form
<script>
function handleFormSubmit(formObject) {
google.script.run.processPk1(formObject);
document.getElementById("myForm").reset();
}
</script>
Here's my .gs code:
function processPk1(formObject) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName("Sheet1");
var data = ws.getRange(2, 1, ws.getLastRow()-1, 1).getValues();
var codeList = data.map(function(r){return r[0].toString(); });
var position = codeList.indexOf(formObject.code); //this is to find the specified existing row position
ws.getRange(position,13).setValue(formObject.pdca);
ws.getRange(position,15).setValue(formObject.teamwork);
ws.getRange(position,17).setValue(formObject.strive);
ws.getRange(position,19).setValue(formObject.cnc);
}
Your response would be really appreciated. Thank you in advance!
EDIT
What I'm trying to do is user could submit a "code" that exist in the Google Sheet, if it found then user could add the "formObject.pdca, formObject.teamwork, etc" on the same row as the "code".
Here's my sample spreadsheet:
https://docs.google.com/spreadsheets/d/15NboiL7aIkUFq267t3yhy9hLRGrdbHI2jAlrIq54SvM/edit?usp=sharing