I’m building a pseudo-app in Google Sheets to allow managers to tell me the status of an employee on their team. Please note: I’m very much a beginner at Google Apps Script, .css and .html, and have been cobbling bits of code together and testing every step of the way until I have something that works.
Currently, the sidebar UI requests an employee ID (input<>) and a status update (select<>,). Managers enter this information and click submit. That data is then appended to a log on a different workbook. All that works (so far).
In in the same workbook, I have a table named "Import" and a range named "Confirm" that has all the employee IDs and their names. ID is in Col1, Name is in Col3. This range can be as many as 8500 rows.
What I want to do is modify the script so that once the ID is entered into the sidebar, the associated name appears beneath it. This ensures that they can see if they’ve entered the correct ID or not. They can then proceed with entering the employee status.
As the range can be very large and is updated frequently, I would need to find the most efficient search-and-display function possible. I would also like to build in error messaging to show
Then, I want to collect the employee ID, the employee name, and the status and append it to the log.
I feel very close to the solution, using getRangeByName() and filtering, but I just don’t have the experience yet to make it work. Any suggestions?
(Due to company policy, I’m unable to post any existing code outside our private network, and I’m too novice to properly anonymize field names and URLs, etc.)
2
Answers
Here is an example of using HTML Service to get values from spreadsheet and place values to spreadsheet.
In my example I have a spreadsheet "Import" with the Id and names of all employees. I use an immediately invoked function expressions
(function () {} )();
in my HTML script to get the values from the spreadsheet and store in browser memory. Then when ever the user inputs an Id in the sidebar, I lookup the employee name. I do something similar on the server when the submit button is pressed.Notice in the spreadsheet screen shot the "New" status returned from the sidebar.
I use templated HTML to split the HTM and Javascript into seperate files. The same can be done with CSS.
Sheet Import
Code.gs
HTML_Test.html
JS_Test.html
References
As an alternative you could simply send the Id to the server and return the employee name
Code.gs
HTML_Test.html
JS_Test.html