Select to view content in your preferred language

Survey123 wrong calculations in repeats using Java Script functions

651
5
06-02-2023 05:15 AM
JudithLandry
New Contributor II

Hi,

Since latest releases, I’m struggling with a problem in my java script functions.  

When a question is left blank in a repeat, in the next repeat, the same question value is shifted from the second to the first repeat.

As you could see in my example, if I left question 3 and 4 blank in my first repeat, the value entered for these questions in the second repeat are attributed to the first when calculated with Java Script…

JudithLandry_0-1685706979295.png

Any solutions?

0 Kudos
5 Replies
JudithLandry
New Contributor II

Hi @DougBrowning, could you help me on this?

What am I doing wrong?

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

This is only since the latest release? For me it is somehow logical that the array only receives valid values. Would you expect to have "null" or "none" in those empty positions?

0 Kudos
DougBrowning
MVP Esteemed Contributor

Sorry I do not use javascript in my forms since I work across AGOL orgs.  But your fuction does not make much sense to me.  I could see that it does not store blanks in an array since it is a different data type.

Lets step back and tell us what you are trying to do and then adjust the code or do it a different way,  Are you just trying to show the last values? Use the last repeat values?  There is code for that.  Or if you are just showing them join works well for me.

0 Kudos
JudithLandry
New Contributor II

Thanks for the quick response Doug,

I've built a JS function to validate responses in a form by comparing answers from many questions within the same repeat. Example:

If you answer the first question, you must answer questions two and three.

The response will also be used to validate the following questions.

If you do not answer the first question you can skip the others or not.

And this for each repeat in my form. That’s why it is so important to have “undefined” value for unanswered questions.

This was perfectly functional in earlier releases.

Is this a bug?

0 Kudos
DougBrowning
MVP Esteemed Contributor

It may handle blanks differently now I do not know.

You may be able to update the code to something more like this

https://community.esri.com/t5/arcgis-survey123-questions/prepopulate-answers-in-a-repeat-with-last-v...

Picking out the values vs just a big array.  Hope that helps