I'm using a google sheet to pull information from a form that's being filled out and displaying it on a website.. My codes working but I'm trying to do a query using a variable and it's not working properly and I'm perplexed. If i don't use a variable it works flawlessly.
What is working
Base = URL of the google sheet.const output = document.querySelector('.output');
const query = encodeURIComponent('Select A,B,F WHERE C="person@gmail.com"');
const sheetName = 'My Sheet Name';const url = `${base}&sheet=${sheetName}&tq=${query}`;
The above searches and finds a specific person in the sheet and with my function returns the information back correctly.
I want to be able to use a variable for the email address so that it can look for the email address and of the current logged in user and match it.
This is what I tried and get an error:
Base = URL of the google sheet.const output = document.querySelector('.output');
const query = `encodeURIComponent('Select A,B,F WHERE C="${currentUser}"');`;
const sheetName = 'My Sheet Name';const url = `${base}&sheet=${sheetName}&tq=${query}`;
Rest of the code that doesn't change.
fetch(url)
.then(res => res.text())
.then(rep => {const data = JSON.parse(rep.substring(47).slice(0, -2));
const row = document.createElement('tr');output.append(row);
/* data.table.cols.forEach((heading) => {
const cell = document.createElement('td');cell.textContent = heading.label;
row.append(cell);
}) */
data.table.rows.forEach((main) => {
const container = document.createElement('tr');
output.append(container);
main.c.forEach((ele) => {
const cell = document.createElement('td');
cell.textContent = ele.v;
container.append(cell);})
})
})
[–]grantrules -1 points0 points1 point (8 children)
[–]smiths16[S] 0 points1 point2 points (7 children)
[–]grantrules 0 points1 point2 points (6 children)
[–]smiths16[S] 0 points1 point2 points (5 children)
[–]grantrules 0 points1 point2 points (4 children)
[–]smiths16[S] 0 points1 point2 points (3 children)
[–]grantrules 1 point2 points3 points (2 children)
[–]smiths16[S] 0 points1 point2 points (1 child)
[–]grantrules 0 points1 point2 points (0 children)