The Output tab holds the complete query formula and generates the output based upon the query supplied to the Query tab by the web app
WebApp
The web app simply supplies the query written in the AI2 app as a parameter and pastes it to the Query tab, which then generates the output
The web app grabs the query output and returns it to the AI2 app as responseContent
function doGet(e) { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('QUERY'); var sh = ss.getSheetByName('OUTPUT'); var query = e.parameter.query ; sheet.clearContents(); sheet.appendRow([query]); var output = sh.getDataRange().getDisplayValues(); return ContentService.createTextOutput(output);}//for use with AI2function doPost(e) { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('QUERY'); var sh = ss.getSheetByName('OUTPUT'); var query = e.parameter.query ; sheet.clearContents(); sheet.appendRow([query]); var output = sh.getDataRange().getDisplayValues(); return ContentService.createTextOutput(output);}
You need the doGet (for testing with a PC browser) and the doPost (for use with the AI2 app)
Make sure you publish the script as a web app, so that it runs as you (the owner of the google sheet) but to be accessed by anyone, even anonymous, and update to a new version and re-publish every time you make a change to the script, if you need to...
to test using your PC browser use a url like this:
https://script.google.com/macros/s/AKfycbyp99OV0O2xKVLAq34c-lUmaNml9T0yTZvN7ELSKGryOcu9F6s/exec?query=SELECT B,C,D,E where B contains 'Alana'
AI2 App
BLOCKS
That is it.
You will need to ensure that any typed or hard coded queries follow the google query language syntax: https://developers.google.com/chart/interactive/docs/querylanguage
Now I know you will have a supplementary question: how do I update a value?
That is considerably more complex, but if you continue to use google apps script, then I would refer you to my HOWTO on that!
//for testing with PC browserfunction doGet(e) {
//lock sheet to prevent concurrent changes var lock = LockService.getPublicLock(); lock.waitLock(5000); var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('KUNJ_DATA'); var sh = ss.getSheetByName('ROWQUERY'); var sht = ss.getSheetByName('ROWOUTPUT'); sh.getRange("A3").setValue(e.parameter.name); var data = [ [ e.parameter.timestamp, e.parameter.name, e.parameter.id, e.parameter.pass, e.parameter.email, e.parameter.ac ] ]; var row = sht.getRange("A1").getDisplayValue(); sheet.getRange("A"+parseInt(row)+":F"+parseInt(row)).setValues(data); return ContentService.createTextOutput("Success"); //release spreadsheet for editing lock.releaseLock();
}
//for use with AI2function doPost(e) {
//lock sheet to prevent concurrent changes var lock = LockService.getPublicLock(); lock.waitLock(5000); var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('KUNJ_DATA'); var sh = ss.getSheetByName('ROWQUERY'); var sht = ss.getSheetByName('ROWOUTPUT'); sh.getRange("A3").setValue(e.parameter.name); var data = [ [ e.parameter.timestamp, e.parameter.name, e.parameter.id, e.parameter.pass, e.parameter.email, e.parameter.ac ] ]; var row = sht.getRange("A1").getDisplayValue(); sheet.getRange("A"+parseInt(row)+":F"+parseInt(row)).setValues(data); return ContentService.createTextOutput("Success"); //release spreadsheet for editing lock.releaseLock();}
aia file also attached
https://docs.google.com/spreadsheets/d/1CIC48yKDb4pMIyZOvoA7thpDpa7G39Nc11CLOCXMyNA/edit?usp=sharing
var rng = sheet.getRange("<Cell Reference>");
rng.setValue(query);