The "Scan Code" button is replicating a scanned code, using a list of the codes in the spreadsheet
You would replace this with blocks and components for your scanner, and feed the result to the Web1.Get
SELECT * where A contains 'textbox1.text' and B contains 'textbox2.text'
This way you have full and easy control over the layout and format of the output sheet. I have frozen row 1, this ensures that this row is displayed on all pages.
You will see the query equation (copy this to your spreadsheet) pulls in the value from Sheet3 to carry out the query. It is this value we will update using the webapp
2. Web App
Use a bound script (so go to Tools > Script Editor to create a new project)
A variation on code used a lot for adding data to spreadsheets from AI2
Just needed to clear the contents of the sheet each time to ensure the value is replaced and not added
and to provide a responseContent of the query value back to the AI2 app
//for testing with PC browserfunction doGet(e) { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheets()[2]; var id = e.parameter.id ; sheet.clearContents(); sheet.appendRow([id]); var output = sheet.getDataRange().getDisplayValues(); return ContentService.createTextOutput(output[0][0]);}//for use with AI2function doPost(e) { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheets()[2]; var id = e.parameter.id ; sheet.clearContents(); sheet.appendRow([id]); var output = sheet.getDataRange().getDisplayValues(); return ContentService.createTextOutput(output[0][0]);}
The script needs to be saved as a web app, run by the owner of the spreadsheet, but accessible to "anyone, even anonymous". You will need to give permissions to run the script
Once published get the url to the script for your AI2 app
The reason for the doGet AND the doPost is because if you submit via a PC browser this preforms a "get", whilst in AI2 this performs a "post"
You can test in PC browser to make sure it works with a url like this:
Right, that is all the non AI2 work done!
3. AI2 App Components and Blocks
For my example, I used a spinner that contained the client IDs i.e. A,B,C
Your app will apply this ID based on their login to the app
For testing i simply select a client ID, then press the button to Download the PDF
We need to add two more web components, one for the call to the web app, the other to call the pdf
BLOCKS
When the webapp has worked, it will report the value of the cell in Sheet3 e.g. A,B,C
and compare this with the value selected in the spinner.
If these are the same then it will initiate Web3 to download a pdf of the filtered results
if not, then to display a message
Files in this example as saving to the root folder of the sdcard
note: if the webResponseFileName is the same as a file that already exists, it will overwrite that file.
SCREENS
That is it ! Enjoy