MAIN GOAL:
- Have an inventory system of QR Codes that, when scanned, directs to a Google Web App URL with a query string
- This Web App searches a spreadsheet for the query string parameters and redirects to the cell that matches the parameter
Note that I can not simply use a URL linking to a cell. Rows are subject to be deleted as items sell. If a QR code directs to A3 and the item in A2 sells, then the item in A3 would become A2.
My problem is that I can't get the web app to redirect to the spreadsheet.
Here is my sheet & this is the code I'm using for the web app
function getCell(item, url){
var sheet = SpreadsheetApp.openByUrl(url).getSheetByName("Sheet1");
var lastRow = sheet.getLastRow();
var range = sheet.getRange('A1:A' + lastRow).getValues();
for(var i = 0; i < lastRow; i++){
if(range[i] == item){
return 'B' + (i + 1);
}
}
}
function doGet(e){
var sheetUrl = "https://docs.google.com/spreadsheets/d/1K6xva3BRzxTAchXi1iseU0MiYCM4luN4edXCgmEv8MU/edit#gid=0";
var cell = getCell(e.parameter.item, sheetUrl);
return HtmlService.createHtmlOutput('<script>window.location.replace("' + sheetUrl + '&range=' + cell + '"</script>');
}
I'm trying this URL https://script.google.com/macros/s/AKfycbwdIZ8xbtf9iBHvNehcbJiYUE1E1gvDR7dyjPRM2CCGH1q_IwQ/exec?item=Dumbell_4
And it doesn't take me past the web app page.