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.
Solved! Go to Solution.
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.
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.
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.
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.
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.
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.