GoogleAppsScript - customfunction completion works randomly - google-apps-script

For a few days I've tried to understand why the auto-completion (in the sheet) is working for my customfunction in one Google Sheet and not in another one.
I even copied/pasted the code in the 2nd .gs but no in the second Spreadsheet I can only see original built-in functions.
I did put the #customfunction in my JSdoc of course.
You can see my 2 screenshots.
I've tried a lot of things around casing and spaces and checked every differences between the 2 sheets.
There is none. I'm out of ideas. Please help me figure it out!
Please note that the function workfs perfectly if I enter the formula manually 'till the end.

Related

Why do my Google Sheet custom functions require this weird workaround?

I’m creating custom functions in Google Sheets using their google apps script language. I’ve done my development on a laptop and it seems to work correctly.
However, when I open the sheet on my mobile device (iOS), the cell output for my custom functions get stuck at “Loading…” forever and never load. But I discovered this weird workaround, but I don’t know why it works or if there’s a better way: if I make a small, trivial change to one of the input cells, then close the sheet and reopen, the sheet will be correctly updated.
Note that if I just make a change to a cell, or add/delete a column etc, without closing and reopening, to force an update, it will still get stuck at “Loading…”.
Also note that if I close and reopen the sheet without making any change, it will still get stuck.
Any ideas of what’s going on here, and if there’s a better way to get my custom functions to correctly update without timing out?
I searched online for solutions, couldn’t find anything.
Update: Example sheet located at this link:
https://docs.google.com/spreadsheets/d/12nm9EwuzqaN0jYUv75CquMhrcUGlVsmEPFoWd92yuWo/edit
Look at the “SeasonTest” tab, cell AS5. On a mobile device it always shows “Loading…” (unless the above workaround is used), but works fine on a desktop

Edit cell above cell that called a function?

I'm using Google Apps Script to make a function that will be called in a Google Sheet. The function does some auto calculating for a spell effect. Some spells need the player to provide extra info (How many people are you shielding, etc) and some don't need any additional inputs. If extra info is needed, the user provides it in the cell directly above the cell that calls the function. I'll call this the "input cell" for clarity. The "function cell" is the one that calls the function, directly below the input cell.
My question is this: if the extra info is unneeded, as determined by conditionals within the function, how do I overwrite the contents of the input cell with '-'? I can't put a formula within that cell directly, because the user would overwrite the formula when entering the additional information. The function also returns a value to the cell that called it.
I've tried a bunch of techniques but I can't figure out how to do it.
I tried returning an array of both values, but it flows downwards instead
of upwards, and I couldn't find anything for "return array offset
upwards" or something to that effect.
I can't use absolute references
like "L17" because the function can be called from many places on the
sheet, and it also only needs to mess with the cell directly above it.
using setValue() or setValues() threw a "no permission" error.
I would attach my code, but it's a mess of half-deleted attempts that didn't work, and wouldn't be much help at all. I also don't want to ask anything too specific, for fear of running into the https://xyproblem.info problem. I just want to be able to have a function edit the cell directly above it, and I don't care about which technique gets that accomplished.
Any help is greatly appreciated. Thank you!
No cell can contain both a formula(or a output of a formula) and simultaneously contain a user entered value. That was always the case with any spreadsheet, Excel or Google sheets or any other. It's one or the other. Choose one and redraw your logic!
For your specific problem, if you can reflow your logic, you might try simple triggers like onEdit.

Activating a new cell not working within Google Sheets onSelection(e) execution?

Is there some way to force the selection of another cell (e.g. A1) after someone has selected a different cell (e.g. B2)? If i use a simple ...getRange(1,1).activate() code, it works when I hit "Run" in the script editor, but not when a selection is made in the real spreadsheet. Please help?
I've basically written a long "onSelection" code that allows someone to mark their answers to a trivia game as "Correct" or "Wrong" by clicking on the corresponding cells. (I do this with onSelection(e) because buttons don't work on mobile.)
However, if they get two answers correct in a row, onSelection(e) doesn't work because they've already selected "Correct" the first time. I want the code to select 'A1' automatically so it's ready for their next Correct/Wrong input.
A code as simple as the following works when I select any cell in Google Sheets and then hit "Run" in the script editor, but it doesn't not work when I select a cell with my mouse.
function onSelectionChange(e){
var sheet = SpreadsheetApp.getActiveSheet()
sheet.getRange(1,1).activate();
}

Today custom function stops working in all google spreadsheets, any idea why? [duplicate]

I have a Google Apps Script custom function, very simple:
function sharesBurned(sharesToSell) {
return "tree"
}
Obviously, this works when I test it in Apps Script. In my sheet, when I call it in a cell, sharesBurned(2), for instance, it sometimes returns "Loading", and in the upper right hand corner of the cell, a red triangular sign appears that, when hovered over, reads: "Error - Loading data...".
I know there have been several threads on this, but they are pretty old, and I've tried all the suggestions already to no avail, namely:
Changing the function name
Refreshing the spreadsheet
Toggling Parameter Cell
Duplicating the spreadsheet
Clearing Browser cache / cookies
To be clear, the function loads in the cell seamlessly half the time and the other half is stuck like this. I highly doubt it's an issue with the script itself so this is likely some weird bug (caching? no clue) with Google Sheets.
This seems to be a issue on Google's server. There is already an active report about Google sheets custom functions stuck in loading. You may want to click the star icon on the top left of the issue report to indicate that you are also being affected by the issue.
Other related issues:
Apps script taking too much time to read from Google sheets
Apps script taking too much time to read from Google sheets charts

Google scripts unhideRows not working

I have a script for Google Sheets I am working on. I realize there are better ways to do what I am attempting (cough html/database cough), but I am required to make this spreadsheet work.
In short, I am trying to hide and unhide rows dynamically. There does not appear to be a way to get filters to update without redoing them, so I am attempting to use hideRows to hide them and unhideRows to reveal them as needed.
The hideRows command works below. The unhideRows command does not. At this time, they are literally this close together in the code. Originally, I was hiding on one sheet and unhiding on another, but set up like this to troubleshoot. There is no filtering on this sheet (because it didn't work, I turned it off). I tried setting the value in unhideRows directly to the value tested instead of a variable.
The row in question hides, but does not unhide.
I tried unhiding a different row just in case google was fumbling with hide this, unhide it back to back. I am not getting unhide to work.
{ //thisRow = the row number of a range, in this case 2 if output to screen
pImages.hideRows(thisRow);
pImages.unhideRows(thisRow);
}
Apparently, the answer is not to unhideRows() which is the one the documents alluded to, but showRows () which does make more sense in everyday language. Thanks again to Mr.Houdini on the Google forums.