Select to view content in your preferred language

Restrict Date Entry Based on Previous Question

1278
9
Jump to solution
11-08-2022 07:58 AM
ZachBodenner
MVP Regular Contributor

Hello,

I am trying to restrict a date range based on a previously entered date. Here's the goal:

Question 1: Enter a date at least seven days from today.

Question 2: Enter a date less than two months (62 days) from the date entered in Q1.

The setup: Survey123 Connect, survey published to Enterprise Portal 10.8.1

Constraints:

Q1: .>date(decimal-date-time(now()) + 7)

Q2: (.>=${Q1}) and (.<=(${Q1} + (1000 * 60 * 60 * 24 * 62)))

 

When published, Q1 works fine, but no date entered into Q2 is accepted by the form (no errors when saving .xls form or publishing).

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

Are you trying to constrain from today until 14 days from now?  That is what is looks like. If so this works for me

${testdate} >= now() and ${testdate} <= date(decimal-date-time(now()) +  14)

Hope that does it

View solution in original post

9 Replies
DougBrowning
MVP Esteemed Contributor

Try changing all your . to ${Q2}  sometimes .<= or others gets confused with HTML and causes issues.  Esp in the web form.  Being specific vs just the . can help.

0 Kudos
ZachBodenner
MVP Regular Contributor

So ({Q2}>=${Q1}) and ({Q2}<=(${Q1} + (1000 * 60 * 60 * 24 * 62))) ?

That gives me an error converting XLSForm

ZachBodenner_0-1667927465159.png

ZachBodenner_1-1667927489104.png

ZachBodenner_2-1667927501969.png

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

you forgot the $

0 Kudos
ZachBodenner
MVP Regular Contributor

Ugh forgive me that oversight. Still getting the same problem in the form though.

0 Kudos
DougBrowning
MVP Esteemed Contributor

So is it just not getting stopped for blank for Q2?  you can make Q2 required or add to the constraint ${Q2} != ''

I think the calc is not firing when the field in blank.

0 Kudos
ZachBodenner
MVP Regular Contributor

Hm, so it is a required question. I also tried setting a default entry of today() thinking maybe you're right with the last comment there but that didn't do anything either. Where in the constraint would I add ${Q2} != ''? Would that have much a different function than setting a default entry?

Additionally, I tried using this constraint: (.>= today()) and (.<=(today() + (1000 * 60 * 60 * 24 * 14))), since ESRI documentation spells it out specifically. That actually gives the same problem in the form (again, no error when updating the xls form). No date is accepted.

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Are you trying to constrain from today until 14 days from now?  That is what is looks like. If so this works for me

${testdate} >= now() and ${testdate} <= date(decimal-date-time(now()) +  14)

Hope that does it

ZachBodenner
MVP Regular Contributor

No, I was just trying to see if I could get anything to work in the constraint for Q2. 

However, your example actually works, which is interesting. I wonder why it needs to be decimal time? So ultimately my successful constraint is:

${Q2} >= ${Q1} and ${Q2} <= date(decimal-date-time(${Q1}) + 62)

DougBrowning
MVP Esteemed Contributor

Dates are a different data type so you cannot just do math on them.  Just like a string - 2 makes no sense.  I will admit I do not know the exacts here either I always open up the form I got it to work in and copy paste :).

0 Kudos