I want to launch a modal once the value of checkbox is change to True, I already tried to create function for that but once I checked the checkbox it doesn’t show anything. I keep on changing and adjusting my codes but I really can’t find where I go wrong. Please someone help me with my codes. Thanks!
Here are all my Function Codes that created:
let folderId = '1uQjcvYKOdbpnD3AybwN4KTKQeFfun_wB';
function onOpen() {
let ui = SpreadsheetApp.getUi();
ui.createMenu('Script Menu')
.addItem('Upload Files','uploadFile')
.addToUi();
}
function uploadFile() {
let window = HtmlService.createHtmlOutputFromFile('Upload.html');
window.setWidth(600);
window.setHeight(400);
SpreadsheetApp.getUi().showModalDialog(window,"Upload File");
}
function saveFile(e) {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let blob = Utilities.newBlob(e.bytes,e.mimeType,e.filename);
let folder = DriveApp.getFolderById(folderId);
let file = folder.createFile(blob);
let fileName = file.getName();
let fileUrl = file.getUrl();
let sheet = ss.getSheetByName("Request Input").getRange('B10');
sheet.setValue(fileUrl);
return [fileName,fileUrl];
}
function checkBox() {
const activeCell = SpreadsheetApp.getActiveSpreadsheet().getActiveCell()
const reference = activeCell.getA1Notation()
const sheetName = activeCell.getSheet().getName()
const activeValue = activeCell.getValue()
if (reference == "B10" && sheetName == "Request Input" && activeValue == true)
{
uploadFile();
activeCell.setValue(false)
}
}
And here is my HTML Code for the function code:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div id="form">
<div id="fileUpload" class="mb-3">
<input id="file" type="file" onchange="saveFile(this)" />
</div>
<div id="progressSpinner" class="spinner-border" role="status" style="display: none;"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous">
</script>
<script>
function saveFile(f) {
document.getElementById('progressSpinner').style.display = 'block';
const file = f.files[0];
const fr = new FileReader();
fr.onload = function (e) {
const obj = {
filename: file.name,
mimeType: file.type,
bytes: [...new Int8Array(e.target.result)]
};
//google.script.run.withSuccessHandler(data => success(data)).saveFile(obj);
google.script.run.withSuccessHandler(google.script.host.close).saveFile(obj);
}
fr.readAsArrayBuffer(file);
}
function success(data) {
document.getElementById('progressSpinner').style.display = 'none';
document.getElementById('fileUpload').innerHTML = `<strong>File Uploaded Successfully</strong><br /><a target="_blank" href="${data[1]}">${data[0]}</a>`
}
</script>
</body>
</html>
I really want to make my code work. I already tried to change names and still it doesn’t work. Can anyone please help me to find whats wrong with my codes and how to fix it. I already tried many time to fix it but I really can’t. Please help me guys. I already put everything here. You can ask me if you need more details to help me with my code. Thank you so much!