Google-sheets – How to reference existing formulas from custom formulas in Google Spreadsheet Scripts

formulasgoogle sheetsgoogle-apps-scriptgoogle-sheets-custom-functionworksheet-function

I want something essentially like this:

function contains(arg1, arg2) {
  return NOT(ISERROR(search(arg1, arg2)));
}

But NOT and ISERROR are undefined even though using =ISERROR(…) works in the spreadsheet view.

How do I build custom formulas that can reference and combine existing formulas?

Best Answer

Google Sheets built-in functions can't be used on Google Apps Script but they could be used as arguments of custom functions and custom functions could be used as arguments of them.

It's worth to note that some Google Sheets built-in functions have direct JavaScript equivalents while others don't. By the other hand as Google Apps Script runs only on Google servers, using a built-in function usually is way faster than a custom function.

Knowing the above it doesn't make sense to use a custom function that does the same as a formula made only with built-in functions.