555
Views
4
Comments
Solved
How to use "NullDate()" in a validation?
Question

I'm following the guided path on "Becoming a Traditional Web Developer" and I'm working on 7.5, i.e. I'm practicing adding validations to forms and such. The exercise wants me to add a validation that verifies that a person's date of death, if specified, does not precede the date of birth:



I've tried using NullDate() for this as can be seen below, but it does not appear to be working out well.



So I'm using:

PersonForm.Record.Person.DateOfDeath = NullDate() or
PersonForm.Record.Person.DateOfBirth > PersonForm.Record.Person.DateOfDeath

What am I not doing right?

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi Iwvk1994,


the true branch of your if node is probably going to an assign that sets the input.valid to false, right ?

So the condition of the if should be true if a wrong combination of dates is given.

As you wrote the condition now, it's true when DateOfDeath is empty, and so the validation will fail, when in fact you want the validation to pass if no DateOfDeath is given.  You only want it to fail if a DateOfDeath is given and it comes before DateOfBirth.

So that translates into 


not(PersonForm.Record.Person.DateOfDeath = NullDate()) and
PersonForm.Record.Person.DateOfBirth > PersonForm.Record.Person.DateOfDeath

Hope this helps,

Dorine

a tip : when you get more complex conditions, try to first just say in plain English what it is you want to happen.


2021-08-12 11-00-27
Nordin Ahdi
 
MVP

Hi,

In order to validate the Date of Death, if defined, is later than the Date of Birth, your validation should be:

PersonForm.Record.Person.DateOfDeath <> NullDate() AND
PersonForm.Record.Person.DateOfDeath < PersonForm.Record.Person.DateOfBirth

This is because when the DateOfDeath is not set by the user, the bound variable will assume the Null Date value, that is 1900-01-01. So now your validation is making sure if the Date of Death is filled in by the user, it needs to be later than the Date of Birth.

Hope this helps!

Regards,

Nordin

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi Iwvk1994,


the true branch of your if node is probably going to an assign that sets the input.valid to false, right ?

So the condition of the if should be true if a wrong combination of dates is given.

As you wrote the condition now, it's true when DateOfDeath is empty, and so the validation will fail, when in fact you want the validation to pass if no DateOfDeath is given.  You only want it to fail if a DateOfDeath is given and it comes before DateOfBirth.

So that translates into 


not(PersonForm.Record.Person.DateOfDeath = NullDate()) and
PersonForm.Record.Person.DateOfBirth > PersonForm.Record.Person.DateOfDeath

Hope this helps,

Dorine

a tip : when you get more complex conditions, try to first just say in plain English what it is you want to happen.


2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello,

I think that your validations are not entirely correct :)

First, the statement says that you want to verify that the DateOfDeath variable is specified. So, you want to validate that the value is different of null date and not equal.

Then, the statement says that you want to verify that the DateOfDeath variable (if specified) is later than the DateOfBirth variable. So you need to execute an and condition instead of an or.


Try to use something like this:

PersonForm.Record.Person.DateOfDeath <> NullDate() and
PersonForm.Record.Person.DateOfBirth > PersonForm.Record.Person.DateOfDeath


Let me know if you have any further questions.


Kind regards,

Rui Barradas

UserImage.jpg
Christian Allsopp

Problem is, if you want to search for all the people who died in 1900-01-01, you're pretty much screwed.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.