Hi,
i love this feature: Custom actions | Metabase Documentation
It would be realy awesome to be able to validate a litte bit what user will “put” to this variables… so some regex to check.
Would this be possible?
Thx!
Erik
Hi,
i love this feature: Custom actions | Metabase Documentation
It would be realy awesome to be able to validate a litte bit what user will “put” to this variables… so some regex to check.
Would this be possible?
Thx!
Erik
(EDIT) There’s no in-Metabase validation at the moment, though it would be nice. I don’t think anything in Metabase uses regular expressions, but allowing us to attach a custom expression as a validator might be a low-effort way to get it.
Mechanically possible, but it will depend on what you want the reaction to an invalid value to be, and what your database engine can do.
One way is to use a WHERE clause to check the variable’s value, which if it fails the check, nullifies the command. This works for most SQL engines but doesn’t give any feedback to the user when validation fails. The exact method will depend on the DML used; INSERT ... SELECT ... WHERE or UPDATE … WHERE.
An alternative, if your database engine supports it, is to write a user-defined function using the engine’s native scripting language (T-SQL, PL/SQL, PL/pgSQL, etc.), which allows you to return error or throw an exception on a validation failure. The error will be displayed to the user.