I’m developing an Apps Script WebApp that includes an upload function. This function should allow users to upload a file from their machine to Google Drive and allocate it to a specific folder based on selections in dropdowns in the UI. For example, if a user selects Folder A and Subfolder B, the file should be uploaded to Subfolder B inside Folder A.
However, I’m encountering the following error for some users:
Cannot read properties of undefined (reading 'getFoldersByName')
userCodeAppPanel:54
Uncaught SyntaxError: Unexpected token 'C', "Cannot rea"... is not valid JSON
at JSON.parse (<anonymous>)
at handle_res (userCodeAppPanel:56:28)
at userCodeAppPanel:48:17
at yh (user.js:139:334)
at 642176320-mae_html_u.mae_html_user.js:32:276
at kf.N (user.js:98:380)
at Cd (user.js:60:477)
at a (user.js:58:52)
The weirdest part is that this error only occurs for some of my users. Note that both affected and unaffected users have the same access rights to the folders and the script. Here are the steps I’ve taken so far to troubleshoot this issue:
Reauthenticated affected users to the script.
- Removed affected users from the access rights to the folders and then added them back.
- Ran a script to test the upload function alone for the affected user. The error message indicated that the folder was not found, meaning the account couldn’t find the folder by name. However, after a few minutes of not touching the source code and just running the script again, it suddenly started working normally for that account.
Despite these efforts, the issue persists for some users and remains resolved for others without any apparent reason. I’m seeking help to understand why this error is occurring and how to resolve it.
Additional Context:
- Apps Script environment: WebApp
- Google Drive permissions: All users have the same access rights
- Error consistency: Randomly occurring for certain users
Eduardo Bertrand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1