We have written a custom Javascript function to parse lists of coordinates defining a polygon from several websites. The function parses out the parts of DMS coordinates and converts them to DD coordinates. They are then re-concatenated into a semicolon-separated list of space-separated coordinate pairs, which we would like to input as a calculation for a geoshape field.
The function has been tested in both a browser console log and in the Scripts tab of Survey123 connect and returns the expected list with no errors, however, when the pulldata call of
pulldata("@javascript", "convertCoords.js", "convertCoordString", ${dms_string}, ${country})
is put into the calculation cell for the polygon field, it defaulty returns an error:
@javascript error:TypeError: Cannot read property 'split' of undefined in convertCoords.js:convertCoordString
Once you enter a value into both of the fields used in the function and hit 'enter', the function calculates the expected string. But, it seems that the error is causing an XLSX error that won't let the survey be saved when the resulting field is placed in the calculation field for the geoshape question.
I've attached the Javascript function and samples of each DMS coordinate string (${dms_string}) form and its corresponding ${country} values are included in the comments section at the top of the script file. Is there something that can be changed in the script so that it doesn't defaultly calculate an error in the Survey123 and consequently calculates the geoshape quesiton?
Solved! Go to Solution.
In case anyone else runs into a similar problem and comes across this post, we found a way to get the calculation to work without changing the JS function. To prevent the pulldata calculation from calculating with an error when the input fields hadn't been filled out yet, we set that field to only be relevant if the final field used in the calculation has a value in it using the following statement in the 'relevant' column of the XLSForm:
string-length(${dms_string})!=0
With this change, the pulldata calculation doesn't run until the necessary fields are filled out, preventing the error from appearing and allowing us to publish the survey!
When I use pulldata it gives me DD right away. Maybe change the settings of the map in 123 to DD? Tried that?
pulldata("@geopoint", ${PitLocation}, "x")
Thanks for the reply @DougBrowning! Unfortunately, I had updated that setting for the survey, but because we are trying to use a Javascript function to convert a list of DMS coordinates like this
36-56.00N 023-29.00E;36-42.00N 023-32.00E;36-41.00N 023-48.00E;36-47.00N 023-55.00E
to a list of DD coordinates like this
36.93333 23.48333;36.70000 23.53333;36.68333 23.80000;36.78333 23.91667
this setting doesn't resolve the error returned by the pulldata calculation.
In case anyone else runs into a similar problem and comes across this post, we found a way to get the calculation to work without changing the JS function. To prevent the pulldata calculation from calculating with an error when the input fields hadn't been filled out yet, we set that field to only be relevant if the final field used in the calculation has a value in it using the following statement in the 'relevant' column of the XLSForm:
string-length(${dms_string})!=0
With this change, the pulldata calculation doesn't run until the necessary fields are filled out, preventing the error from appearing and allowing us to publish the survey!