I have a function (addEmailsOfStudentsToBCC(e)) which fetches e-mail adresses from a Google sheet pending on the choices of the user on a formInput (select). If gets the e-mailadress of each selected student, pushes in a array and in the end the array gets pushed to the BCC of a draft e-mail.
Everything works like a sharm on the Gmail app on my laptop. When opening the same add-on with the same function on my mobile device (in Gmail-app)… It throws an Type errror:
TypeError: Cannot read properties of undefined (reading 'forEach') at addEmailsOfStudentsToBCC(Main:174:16)
Logs also show that e['formInputs']['studentPicker']
is null on the mobile device but it returns an array with the chosen selection on a laptop.
The crazy thing is i have another function where teacher can select classes which use a similar way of working (e['formInputs'['classPicker'])
and that one works on laptop and mobile.
function addEmailsOfStudentsToBCC(e) {
let studentsToMail = e['formInputs']['studentPicker']
let toRecipients = []
studentsToMail.forEach((e) => {
var listOfEmails = getMaillistFromClass(e)
toRecipients.push(listOfEmails)
})
var response = CardService.newUpdateDraftActionResponseBuilder().setUpdateDraftBccRecipientsAction
(CardService.newUpdateDraftBccRecipientsAction()
.addUpdateBccRecipients(toRecipients))
.build();
return response;
}
I tried to check the logs but i’m kind of hopeless at the moment
Dennis Verhasselt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Google Add-ons Restrictions
Since it wasn’t stated what type of add-on you’re using, Google actually has two types of add-ons: Google Workspace Add-ons and Editor Add-ons. This information is specified on Types of add-ons where it states that
There are two types of add-ons you can build: Google Workspace Add-ons and Editor Add-ons. For more information about each, see Add-on types.
According to Google Workspace Add-ons Restrictions
For the time being, Google Workspace Add-ons function on desktop web clients. Contextual triggering (that is, Gmail message reading) is also supported from within the Gmail mobile app. Non-contextual homepages are not yet available from the Gmail, Calendar, or Drive mobile apps. Google Workspace Add-ons are not available from mobile web browsers.
While Editor Add-ons states that
Editor Add-ons only function in desktop clients, not Android or iOS.
I’m guessing that you’re using a Google Workspace Add-on. The first statement explains why the studentPicker
behaves differently on mobile compared to the classPicker
. You mentioned, The crazy thing is I have another function where the teacher can select classes, which uses a similar approach (e['formInputs']['classPicker']), and that one works on laptop and mobile.
This highlights that it may not work consistently due to the existing restrictions.