googleworkspace / googleworkspace/apps-script-samples
How to have a Google Workspace Add-on homepageTrigger multiple times?
@PierrickVoulet is already working on this.
Since Dec 13, 2023.
- Dominant language
- JavaScript
- Stars
- 5.2k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
We have a Google Workspace add-on that operates via a sidebar, so we use homepageTrigger so that the user can open the sidebar from the right hand menu.
This works well - but only once per page load - so if the user opens the sidebar, closes it and attempts to reopen via the right hand menu we instead get this page:
How instead can we have the homepageTrigger function run every time?
Here is the appsscript.json:
{
"timeZone": "Australia/Sydney",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"dependencies": {
"enabledAdvancedServices": [
{
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}
]
},
"oauthScopes": [
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/documents.currentonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/presentations",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.apps.readonly",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/userinfo.email"
],
"urlFetchWhitelist": [
"https://cm234-wgs-1.icognition.cloud/",
"https://docs.google.com/feeds/download/documents/export/Export",
"https://docs.google.com/spreadsheets/export",
"https://docs.google.com/feeds/download/presentations/Export"
],
"addOns": {
"common": {
"name": "Content Manager",
"logoUrl": "https://cm234-wgs-1.icognition.cloud/CMServiceApiGoogle/TrimIcon/W64h64/trim.png",
"homepageTrigger": {
"runFunction": "showSidebar",
"enabled": true
}
},
"sheets": {},
"docs": {},
"slides": {}
}
}
Here is the function it is calling (when I add a log line at the start of this function it is only ever called once):
function showSidebar() {
var sidebarName = "sidebar";
if (getRecordUri() !== 0) {
sidebarName = "existing_record_sidebar";
}
var ui =
HtmlService.createHtmlOutputFromFile(sidebarName).setTitle(
"Content Manager",
);
getUi().showSidebar(ui);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.