Skip to main content
August 9, 2022
Question

Trying to use a rule inside a validation

  • August 9, 2022
  • 8 replies
  • 0 views

I have a validation on a dateField that I am trying to use a rule inside of the if statement. See below.

validations: {
 if(
    and(
        rule!someRuleThatDoesntWorkHere(a, b, c),
        rule!someRuleThatWorks(a)
    ),
    "message goes here",
    {}
    )
}

I get a "Cast Invalid Could not cast from Rule or Function Reference to Boolean" when I  add the first rule. Is there something I should look for specifically.

8 replies

mikes0011
Brainy
August 9, 2022

At first glance the syntax looks valid - when you open the first rule and run it, does it return a valid (Boolean type) output?

The Expression Guru
brafb6685Author
August 9, 2022

Yes. It does return a boolean output.

mikes0011
Brainy
August 9, 2022

Also check to verify that it still returns a valid boolean response (and not, for example, nulls or an error) for all possible values of "a, b, c" that could be passed in from your interface.  That would include passing in nulls, incorrect values, etc.

Also you could post the code for the rule that doesn't work, and/or a screenshot of its output.

The Expression Guru
harshitb6843
August 9, 2022

Two things

  1. Make sure your rule is returning a boolean value
  2. Wrap toboolean() around both the functions so there isn't any type mismatch error.
brafb6685Author
August 9, 2022

It always returns a boolean, but adding toboolean() gives me almost the same error.

harshitb6843
August 9, 2022

With the error, it looks like somewhere there is a space in the rule name or between the name and the brackets. 
The only way to find it is to isolate the error. Try removing code blocks and see what was causing this issue. Once you find that block, start doing the same in that block too. 

August 9, 2022

both the rules are returning boolean values individually? it will be great if you can share the code of your rules as well