I’m having trouble with a Google Sheets script. I made a button that’s supposed to open a URL in an overlay window. The script runs when I click the button, but the overlay window doesn’t show up. Here’s what I’ve got:
function formOpener() {
var btn = CardService.newTextButton()
.setText('Open Form')
.setOpenLink(CardService.newOpenLink()
.setUrl('my-form-url-here')
.setOpenAs(CardService.OpenAs.OVERLAY)
.setOnClose(CardService.OnClose.RELOAD_ADD_ON));
}
My manifest file looks like this:
{
"timeZone": "America/New_York",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"urlFetchWhitelist": ["my-form-url-here"],
"openLinkUrlPrefixes": ["my-form-url-here"]
}
Can anyone spot what I’m doing wrong? Thanks for any help!
I’ve dealt with similar overlay issues in Google Sheets scripts. One thing to check is whether you’re using the correct CardService methods for a spreadsheet addon. The code you’ve shared looks more appropriate for a Gmail addon.
For spreadsheets, try using SpreadsheetApp.getUi() to create a modal dialog instead. Here’s a quick example:
function formOpener() {
var html = HtmlService.createHtmlOutput(‘<iframe src="your-form-url-here" width="100%" height="100%">’)
.setWidth(600)
.setHeight(400);
SpreadsheetApp.getUi().showModalDialog(html, ‘Form’);
}
This approach should work more reliably for spreadsheet addons. Remember to update your manifest file accordingly if you make these changes.
hey mate, i think ur problem might be that ur not actually returning the button u created. try adding ‘return btn;’ at the end of ur function. also, make sure ur calling formOpener() somewhere in ur code. hope this helps!
I’ve encountered a similar issue before, and it turned out to be related to how the function was being triggered. Make sure you’re creating a custom menu item or a spreadsheet onOpen() trigger to actually call your formOpener() function. Something like this in your Code.gs file:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu(‘Custom Menu’)
.addItem(‘Open Form’, ‘formOpener’)
.addToUi();
}
Also, double-check that your ‘my-form-url-here’ is actually replaced with the correct URL in both the script and the manifest file. If the URL doesn’t match exactly or isn’t whitelisted properly, the overlay won’t open.
Lastly, ensure you’re testing this in an actual Google Sheets environment, not just the script editor, as some functionalities only work when run from the spreadsheet itself.