I am making a web app using google sheets and google app script. My web app have an index page and an input page. There is no problem with inputting the data, however when i try to populate the data from google sheet it displayed undefined value for cells that are empty in the google sheet.
My script is quite long so i attached it here:
https://drive.google.com/drive/folders/1Zl-8UsntRUTlJcnaBuYIgXP2PvD4mIyN?usp=sharing
What i want is, when i click the edit button the form will be populated with the right data and if the data in google sheet is empty then it will just display the placeholder.
Thank you in advance.
2
Answers
To resolve this, you can add a simple check in order to handle empty values.
When populating the form with data retrieved from the Google Sheet, you can modify the code to check if the value is
undefined
or empty, and if so, display the placeholder instead.In the function where you’re fetching the record to populate the form (
getRecordById
), add logic to check forundefined
or empty values and handle them.Here’s a quick example which you can use:
Try modifying your readRecord function as:
I get some of your code to keep your coding style reusing part your searchRecords function.
This is not an elegant solution but, if it works, will give you a hint to found your best solution.