I have developed a simple Google Forms editor add-on that POSTS a Google Form response to a web service that I've created elsewhere. Here is the code for that below:
function onInstall(e) {
ScriptApp.newTrigger("onSubmit").forForm(FormApp.getActiveForm()).onFormSubmit().create();
onOpen(e);
}
function onSubmit(e) {
const items = [];
for (const res of e.response.getItemResponses()) {
const item = res.getItem();
items.push({ "title": item.getTitle(), "response": res.getResponse(), "desc": item.getHelpText() });
}
const response = UrlFetchApp.fetch("https://my-web-service.app/gform", {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify({
"form_title": e.source.getTitle(),
"form_id": e.source.getId(),
"response_id": e.response.getId(),
"items": items,
"timestamp": e.response.getTimestamp(),
}),
"muteHttpExceptions": true,
});
console.log(`Response Code: ${response.getResponseCode()}`);
}
The Problem
Ideally, when the user installs my add-on, the simple trigger: onInstall(e) {} should fire and create my installable trigger. But that isn't happening. The trigger won't install or fire when another user installs my add-on from the Google Workspace Marketplace. Why is that?
I've seen the below previous questions on Stack Overflow:
But these don't really answer my question since they mainly have to do with Google Sheets. My add-on is a Google Forms editor add-on.
It's expected that
The trigger won't install or fire when another user installs my add-on from the Google Workspace Marketplacebecause the documentation of onInstall(e) states that:Here is the link to that documentation: https://developers.google.com/apps-script/guides/triggers#oninstalle
Instead, you can try things like Universal actions to run a function, like in the question Installable Triggers for workspace Addon.