Reputation: 108
This is my JavaScript written in HTML file itself where I want to call a value(Time)
from a function written in code.gs file for getting time from spreadsheet. Also the function written below in JavaScript will run onclick
of the button with the new URL having parameters of
time , the value called from spreadsheet code.gs
<script >
const getTimefromSheet = () => new Promise((resolve, reject) => google.script.run.withSuccessHandler(resolve).withFailureHandler(reject).getTimefromSheet());
async function gettime(){
const getTimefromSheett = await getTimefromSheet().catch(err => console.log(err));
// getTimefromSheett = google.script.run.getTimefromSheet();
console(getTimefromSheett);
return getTimefromSheett;
}
document.getElementById('submit').addEventListener('click', _ => {
var getT = gettime();
addRow();
console.log(getT);
const css = document.getElementById("txt").value;
document.getElementById('submit').href = <?= ScriptApp.getService().getUrl() ?> + `?v=form&input=${getT}`;
});
// google.script.url.getLocation(location);
The fuction which will return time is as follows: code.gs
function getTimefromSheet(){
var sheetname = "Input";
var rang = "C2";
var tr = getDataFromSheet(sheetname,rang);
var timestamp = tr.toString().replace(/\s/g, "");
Logger.log(timestamp);
return timestamp;
}
Kindly let me know that how can one pass the value from spreadsheet to the URL in parameters. I would need the unique URL for every user Hence this is the requirement for the same. I am new to this so how can I achieve?
Upvotes: 1
Views: 80
Reputation: 201388
As a simple modification, how about the following modification?
In this modification, Javascript is modified.
const getTimefromSheet = () => new Promise((resolve, reject) => google.script.run.withSuccessHandler(resolve).withFailureHandler(reject).getTimefromSheet());
document.getElementById('submit').addEventListener('click', async _ => {
var getT = await getTimefromSheet().catch(err => console.log(err));
addRow();
console.log(getT);
const css = document.getElementById("txt").value;
document.getElementById('submit').href = <?= ScriptApp.getService().getUrl() ?> + `?v=form&input=${getT}`;
});
getT
is the value from getTimefromSheet()
.getTimefromSheet()
and addRow()
works fine, and also, <?= ScriptApp.getService().getUrl() ?>
works fine. Please be careful this.Upvotes: 2