Hello all,
We are experimenting with methods of digitizing a workflow that previously involved recording field data by hand, taking a photo of the worksheet, submitting that as an image response in Survey123, transferring the field data to an Excel spreadsheet (also by hand), and then having some Excel macros finish the effort for us. The workflow in question involves a fair amount of algebra and trigonometry, which I attempted to automate as calculations in the survey form so that we could cut out most of the steps outlined above and just have a feature report create a table of all the calculated values from the field. However, I apparently have a reference error in my form and I suspect it has to do with misunderstanding the output of certain calculate fields in the whole sequence of calculations. I am not able to share the entirety of my XLSForm; however, I don't think I need to in order to resolve this issue.
I have a ${positionfactor} field that determines the sign needed to multiply values by, based on specifically where and how the values were collected in relation to the asset. Its calculation cell in the XLSForm is: if(((${guy_a_obs}='direct' and ${guy_a_obs_whole_shift}='right') or (${guy_a_obs}='thru' and ${guy_a_obs_whole_shift}='left')),1,-1). I expected the output of this calculation to be an integer (1 or -1), but I suspect that I am getting the string of each integer instead. ${positionfactor} is used later on in the following formula: (${positionfactor} * ${guy_a_whole_hdist} * (tan(${guy_a_obs_whole_ddconvert}) * 57.295779513)). However, when I look at a record of this survey exported to Excel, I see the following error:
| ReferenceError: positionfactor is not defined in expression: (positionfactor * guy_a_whole_hdist * (tan(guy_a_obs_whole_ddconvert) * 57.295779513)) |
However, there are definitely positionfactor values populated for all records in this particular repeat:
| Determines the actual shift vector based on <FIELD LOGIC> |
| -1 |
| -1 |
| 1 |
| 1 |
| -1 |
| -1 |
| 1 |
| 1 |
Here is the actual definition of positionfactor in the XLSForm (I removed all the blank cells as there are only 4 columns used):
| type: integer | name: positionfactor | label: Determines the actual shift vector based on <FIELD LOGIC> | calculation: if(((${guy_a_obs}='direct' and ${guy_a_obs_whole_shift}='right') or (${guy_a_obs}='thru' and ${guy_a_obs_whole_shift}='left')),1,-1) |
Given all this, the only explanation I can come up with is that S123 is trying to multiply a string by various decimals, and that freaks it out. I am thinking of simply ensuring positionfactor is an integer in the calculation that it is used in (int(${positionfactor} etc etc) - will this do the trick? Or am I way off base here and just missing something obvious?
I think issues like this have tripped me up before, expecting one datatype as output and actually getting another. I know that I have seen others mention it as a significant stumbling block around these forums. Where can I find the documentation on output datatypes in S123 calculations?