Current Value "Cannot read" when using formulas - Best practices

Hi,
Was thinking what is the best approach and also trying to avoid “false errors”. Sometimes when we are using formulas and we use IF conditions or splits, we have some formulas that since that path was not “chosen” it will not have a value and return a “Cannot read properties of undefined (reading ‘result’)”

My thought is, is it better to apply a “ifempty” in this case or from weweb functional/error perspective it is fine to leave it with that “false error”? Thank you.

the if formula it’s not an if statement. the difference is that an if statement will not execute the code if the condition is not met, while the formula (because it’s a function) must evaluate all parameters and then calculate the returned value.
the actual nocode equivalent of an if statement is a true/false split in a workflow.
what happens with the if formula is that often one of the parameters will try to access parameters of a variable that sometimes is undefined and that will cause an error.
there are 2 possible solutions:

  • switch the formula mode to javascript you can still use variables and nocode formulas and you can use real if statements when needed
  • check that the variable is not empty before trying to access its properties, like you suggest

Instead of if, use the ternary operator. Problem solved. Otherwise just use nullish coalescent operator to fall back from undefined to false. Or as Mariano said, switch to JS, but then you gotta ideally declare your vars on top and use them across the formula as reference, otherwise it gets messy super fast.