I'm trying to write some logic for the survey queue, where a repeatable survey would be shown only if no entry is present (has not been filled yet) or if the last completed date was more than 14 days ago.
I tried to write some logic in the Logic Editor in the survey queue, but I seem to only get False results from the datediff function:
if ([survey_name_complete] = 0,
# return True if the survey is not completed
True,
# check if last complete was 14 days ago
datediff([survey-date-completed:survey_name:value], 'today', 'd', True) > 14
)
With a survey not completed ([survey_name_complete] = 0) I expect to return the True value, but when I add the datediff line it starts to always return False.
If survey_name is a repeating instrument, you might need to add the instance smart variables to these. I think you might consider the logic where the _complete status of the first instance is empty, indicating it doesn't exist, and check the completed date of the last instance.
Also, if this is survey queue logic, you want it to return true or false only. So I have simplified it to a single evaluation with OR, which will return true
if there is no first instance or if the last instance's complete date is more than 14 days ago, and false
if neither of those is the case.
So perhaps something like this:
[survey_name_complete][first-instance] <> "" OR datediff([survey-date-completed:survey_name:value][last-instance], 'today', 'd', True) > 14
This is untested. When I get a moment I will try this out in a test project and if it doesn't do what I expect I'll update this answer.