New Tool Radar

AI for Data & Spreadsheets

How to Check Whether an AI-Suggested Apps Script Custom Function Is Needed at All

Check whether an AI-suggested Apps Script custom function is needed, or a built-in formula does the same job.

Schematic with three steps: Write down what the custom function returns; Try the built-in formula first; Keep the script only when no built-in.

Apps Script can add custom functions to Google Sheets, such as a function that doubles a value or fetches a price, and an AI assistant may suggest one for a job a built-in function already does. A custom function needs script access, runs slower than a built-in formula, and cannot edit other cells. Before accepting the script, check whether a built-in formula answers the same question.

What you need

  • The AI-suggested custom function and what it should return
  • The built-in functions that might do the same job
  • One input with a known correct answer

Step 1: Write down what the custom function returns

Read the AI suggestion and write down, in one sentence, the input it takes and the output it returns. If the sentence describes a lookup, a sum, or a text change, a built-in function probably exists.

Step 2: Try the built-in formula first

Write the same calculation with built-in functions in a spare cell and test it on the known input. If it returns the right answer, the script is not needed.

Step 3: Keep the script only when no built-in fits

Keep the custom function only when the job needs something built-ins cannot do, such as calling a web service or a calculation no function covers. Even then, check that the script asks for no access beyond the sheet.

Worked example: synthetic doubling calculation

The table below is a synthetic example. It shows the expected result of checking an AI-suggested custom function; no formula was run.

Check Value Result
Job asked for Double a value Input 21
Custom function suggested =DOUBLE(A1) Needs a script
Built-in formula =A1*2 Same job, no script
Result of both 42 Identical answers

Expected result (UNTESTED). the custom function =DOUBLE(A1) and the built-in formula =A1*2 both return 42 for an input of 21, so the script adds nothing and the built-in formula is kept. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A custom function cannot edit cells other than the one it is called from, and it cannot open other spreadsheets.
  • A custom function must return within 30 seconds or the cell shows #ERROR!.
  • Custom functions do not recalculate when a cell they read through getValue changes, only when their own arguments change.
  • Anyone who can edit the sheet can also edit the script attached to it, so a shared sheet shares its code.

Sources

See all