Dear Survey123 community,
I have a couple of "dateTime" questions with calculations alongside them to assist users.
And in some case the users may manually overwrite these values before submitting.
But, if an user were to view one of those surveys from their 'inbox or sent folder,' it'll display the calculated value, rather than what was submitted.
So, I was wondering whether it is possible to ONLY perform a calculation, if the respective field is empty.
Attached below is a sample calculation.
date-time(decimal-date-time(today()) + 15.29166669)
Thanks,
Gee
Solved! Go to Solution.
I got something like this working by putting if(string-length(respective field)=0,do time calculation, respective field) in the calculation column of the question I wanted calculated. In your simple calculation it would be if(string-length(${respectiveFieldName})=0,date-time(decimal-date-time(today()) + 15.29166669),${respectiveFieldName}). This would make it so the calculated field would do the calculation if the respective field is empty otherwise if the user were to overwrite the respective field it would display the overwrite they did. I hope this helps.
I got something like this working by putting if(string-length(respective field)=0,do time calculation, respective field) in the calculation column of the question I wanted calculated. In your simple calculation it would be if(string-length(${respectiveFieldName})=0,date-time(decimal-date-time(today()) + 15.29166669),${respectiveFieldName}). This would make it so the calculated field would do the calculation if the respective field is empty otherwise if the user were to overwrite the respective field it would display the overwrite they did. I hope this helps.
It works
THANKS so much
Thanks again for the solution.
But, is there a way to make both - calculated and respective fields the same?
I currently get an error when I try and do this.
Thanks,
Gee
Ismael Chivite James Tedrick
Do you guys know if it possible to keep calculated and respective fields the same with the above equation?
Thanks,
Gee
Hi Geethaka,
Can you share a copy of your xlsx form and the error you are getting?
Phil.
Hi Geethaka,
The issue is that you are using the string-length(${startDate}) calculation on the same field ${startDate}. This creates a dependency cycle as there is no answer in ${startDate} until it is selected but you are trying to run a calculation on it before it is selected.
The string-length(${startDate}) would need to be in a following question and reference the previous question, and you can could use null field types to achieve what you are after with your calculations. Using calculations and relevance on the same question is ok, provided you don't create a dependency cycle by trying to run a calculation on the same field the input is required from.
Phil.
Thanks Phil for the explanation.
Gee