I am experiencing difficulties in coding this. I have attempted to use google.script.run
but it's not working as expected. When I click the button "Approved," the data should be sent to a function, but I'm unsure of what steps to take next. I feel stuck and confused about how it all comes together. Thank you for any help!
Index.html
<body>
<div id="tables">
<? var data = getData();?>
<table id="tableShift1">
<caption >Shift1</caption>
<th> ID </th>
<th> Ldap </th>
<th> Action </th>
<? for (var dataList = 1; dataList < data.length; dataList++) {
?>
<tr >
<td><?= data[dataList][0] ?></td>
<td><?= data[dataList][1] ?></td>
<td><button onclick='google.script.run.setApproved(data[dataList][0])' id='btnLdap'>Approve</button></td>
</tr>
<?
} ?>
</table>
</div>
</body>
Code.gs
function setApproved(data) {
var ss = SpreadsheetApp.openById('17lKIhONfEeNogsBhKtGr4zVaLgH0_199-3J3-0tAdcE');
var sheet = ss.getActiveSheet();
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
var headers = values[0];
var ldapIndex = headers.indexOf('ID');
var statusIndex = headers.indexOf('approvalstatus');
var sheetRow;
for( var i = 1 ; i < values.length; i++ )
{
var row = values[i];
if(row[ldapIndex] == data)
{
sheetRow = i +1;
break;
}
}
++statusIndex;
sheet.getRange(sheetRow, statusIndex).setValue('Approved');
}