Need help with sorting values

2285
9
Jump to solution
07-12-2019 01:38 PM
JessikaMcFarland
New Contributor

I am creating forms for a forestry study. We collect the diameters of trees in a plot, among other information. I use the repeat feature for collecting tree data. We sort the trees from largest to smallest to calculate the quadratic mean diameter of the 8 biggest trees. 

I am wondering if it's possible to view/sort the tree entries by largest-smallest diameter, in some sort of table, list, other form, etc besides navigating back to the form submission. Interns may see over 100 trees in a given plot, so navigating the entries by hand to figure out which are largest could be inefficient and tedious in a field setting. 

I'm pretty new to Survey123 so I would appreciate any recommendations. Thanks!

0 Kudos
1 Solution

Accepted Solutions
IsmaelChivite
Esri Notable Contributor

Hi Jessika McFarland

  I put together an XLSForm to illustrate how this could be done. I added a repeat in the survey to capture the diameter of the trees. The survey also includes a calculation that uses a custom JavaScript function to automatically calculate the RMS of the 8 largest diameters from the repeat.  When a survey includes a custom JS function, you must be logged in in Connect or in the Field App to be able to use it.  I hope it helps.

View solution in original post

9 Replies
LanceCole
MVP Regular Contributor

Jessika, 

To my knowledge, that would be beyond the current ability of Survey123.  Survey123 can perform basic functions such as Max, Min, Average, Sum on the all values in a repeat but currently does not have the ability to select or filter prior to performing these functions. That being said, do you need to perform this in the field?

This could be very easily be post-processed on the collected data once submitted.  Not knowing your current workflow, I cannot offer a specific example but would typically use a custom script running in ArcGIS Desktop or Pro. You could even have a place holder in your survey that a script running on the back end could calculate and update the quadratic mean for the eight largest trees for each survey on a nightly basis.

0 Kudos
IsmaelChivite
Esri Notable Contributor

Hi Jessika McFarland

  I put together an XLSForm to illustrate how this could be done. I added a repeat in the survey to capture the diameter of the trees. The survey also includes a calculation that uses a custom JavaScript function to automatically calculate the RMS of the 8 largest diameters from the repeat.  When a survey includes a custom JS function, you must be logged in in Connect or in the Field App to be able to use it.  I hope it helps.

LanceCole
MVP Regular Contributor

Ismael,

Is there documentation available for using this method and was it just implemented in the newest production release?

0 Kudos
JessikaMcFarland
New Contributor

Thank you so much! 

Unfortunately I also lack JS proficiency, and I have not been able to get this to work in the form.

It reads the message:

Error: Qt.createQmlObject(): failed to create object:
c:/Users/jessikamcfarland/ArcGIS/My Survey Designs/QMD test RMS/extensions:2:1: Script file:///C:/Users/jessikamcfarland/ArcGIS/My Survey Designs/QMD test RMS/extensions/JSFunctions.js unavailable

Any ideas?

Thanks a ton - the JS function will be incredibly helpful, just trying to navigate how to implement it now.

 

0 Kudos
JessikaMcFarland
New Contributor

Thanks again, I was able to figure it out over the weekend!

0 Kudos
TaylorMckeeman
New Contributor

Hi Jessika McFarland

Just wondering what you had to do to solve this error? I am having the same problem

Thanks,

Taylor

0 Kudos
JessikaMcFarland
New Contributor

Hi Taylor,

I basically copied the extensions folder with the JS function into my folder for the survey. I was able to edit the function in Notepad to make slight changes, save as a .JS, and it worked pretty well!

The big thing I noticed is that despite the error message in Survey123 Connect, the form works once its downloaded onto your device. If you are receiving similar error messages, you should try downloading the form to assess its functionality. 

Does that answer your question?

Thanks,

Jessika

0 Kudos
TaylorMckeeman
New Contributor

Hi Jessika,

Thanks for your reply! Yeah I did the same thing. The main solution that I found was that when changes were made to the javascript file (or the extensions folder that it was in) I had to completely close out Survey123 Connect and reopen it (not just refresh the form) for the changes to take effect. That might explain why you were having success after the form was published and downloaded to a device, although I can't be sure.

Thanks again,

Cheers

Taylor

ThomasBeers
New Contributor II

Thanks for posting this Jessika, my problem is very similar and I was hoping I could get Ismael to chime in on this. I want to have a list of components (~30) sorted alphabetically in a repeat when I open a survey. The work flow is that components are constantly replaced, so "batteries" end up at the end of the list, making it hard for technicians to locate the component they want to update. By your example above I could use: 

pulldata("@javascript","sort_components_alpha.js","sort_component_alpha", ${COMPONENT})

function sort_component_alpha(ary){
//Sort the array in alphabetic order
var arysorted = ary.sort();
//return
return arysorted
}

In doing this, I would have to create a new element like "component2" to put this pulldata function in the calculation field. Is there anything forthcoming that would allow an alphabetical sort without having to create a new field? This would save me a lot of work! Thanks for your time. 

-Tom 

0 Kudos