Select to view content in your preferred language

Create constraints based on previous answers in survey.

5662
5
Jump to solution
03-29-2021 06:29 AM
PatrickMcGarry1
Emerging Contributor

PatrickMcGarry1_0-1617024161827.png

In Survey 123, I am trying to create a survey answer based on the results of previous answers. For example in the image above, a users chooses the priority level and then the day the defect was reported on. The Due Date for completion has to to be limited to 24HRS/1 Week etc from the defect date based on the responses given. I have tried constraints and calculations on Survey 123 connect, but connect get a solution.

 

1 Solution

Accepted Solutions
UriGilad_EsriAu
Esri Contributor

Hi @PatrickMcGarry1 ,

See attached xlsf with a sample on how to achieve that (sample is for 7 days).

First you need to get the number of days as an integer. You can set this up in your choices or create another hidden field, let’s call it number_of_days to return an integer by using an if statement, for example if(selected(${priority_code},"P1 - 24HRS", 1, if(selected(${priority_code},"P2 – 1WEEK",7, etc.).

Now that you have the days you can create a calculate field and calculate it as

date(decimal-date-time(today()) +int(${number_of_days})

or 

date(decimal-date-time(now()) +int(${number_of_days})) 

Then put a constraint on your completion date field forcing it to be equal or bigger than the calculated field.

Hope this helps, 

Uri

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

View solution in original post

5 Replies
UriGilad_EsriAu
Esri Contributor

Hi @PatrickMcGarry1 ,

See attached xlsf with a sample on how to achieve that (sample is for 7 days).

First you need to get the number of days as an integer. You can set this up in your choices or create another hidden field, let’s call it number_of_days to return an integer by using an if statement, for example if(selected(${priority_code},"P1 - 24HRS", 1, if(selected(${priority_code},"P2 – 1WEEK",7, etc.).

Now that you have the days you can create a calculate field and calculate it as

date(decimal-date-time(today()) +int(${number_of_days})

or 

date(decimal-date-time(now()) +int(${number_of_days})) 

Then put a constraint on your completion date field forcing it to be equal or bigger than the calculated field.

Hope this helps, 

Uri

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

PatrickMcGarry1
Emerging Contributor

Thanks Uri,

I tried updating the XLS form, but it doesn't seem to be accepting the constraints. In the form attached, I have limited the date to one day from today but when I add the due date, it doesn't accept it as valid. Not sure if I am doing this correctly. Any ideas?

Thanks, Patrick.PWAY_Defects.JPG

 

0 Kudos
UriGilad_EsriAu
Esri Contributor

Hi @PatrickMcGarry1,

Just had to shuffle a few lines - see attached xlsf with corrected fields. Note that currently 'P4 Routine Maintenance' = 100 days. Change it in the calculation field to fit the number of days you're after.

Also, consider changing the constraints error messages of the date to something that will explain the reason of error, e.g., 'Completion date must be in 7 days'.

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

0 Kudos
PatrickMcGarry1
Emerging Contributor

Thanks a lot Uri that worked. I also tried changing the choices to integers and that worked also without the need for the number of days calculation. 

Can I also default to the date for the Due Date for Completion. For example, if I select the Priority Code for P1 - 24HRS can this automate the due date for Completion to be 1 day from the Date the Defect was Reported on? I want the due date to be autocompleted based on the Priority Code and the Reported Date.

0 Kudos
UriGilad_EsriAu
Esri Contributor

Hi @PatrickMcGarry1,

Yes, all you need to do is replace

date(decimal-date-time(today())+int(${number_of_days}))

with 

date(decimal-date-time(${date_the_defect_was_reported_on})+int(${number_of_days}))

Note that this solution doesn't work well on the web version, but seems to work fine on the Survey123 app.

Cheers, 

Uri

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

0 Kudos