Select to view content in your preferred language

Challenge question: Looking for a way to display unique values of multiple select questions in a note

1510
8
Jump to solution
10-17-2022 10:38 AM
mrosekulick
New Contributor III

Hi! I'm not sure if this is possible to do or not - but I'm wondering if anyone out there has a creative solution for this. This is not necessarily a requirement for me, but it would be a helpful note for field staff using the survey.

So! I have a couple select multiple fields in a repeat that indicate species of bats that have been found via a couple different survey methods. I want to be able to pull out unique values from those fields across repeats and display what species have been seen at the site. (So at first glance the surveyor will know roughly what to expect.)

BONUS:

The other layer to this is that the species are coded. So the data appear like: "LABL,MYCA,ANPA"

If the note could subsequently read: "Species seen here: Red bat, California myotis, Pallid bat" 

Then that would be super! Maybe this isn't possible, but wanted to pose the challenge to any folks who are Survey Wizards. 

I'm attaching my survey spreadsheet as well. The fields I'm looking to pull from are known_vis and known_acou.

Thanks a bunch!

0 Kudos
1 Solution

Accepted Solutions
Katie_Clark
MVP Regular Contributor

I attached the XLS form, and here are the Javascript functions I embedded in the survey. 

 

function uniqueSpecies (translatedSpecies) 
  {
    var x = translatedSpecies
    x = Array.from(new Set(x.split(','))).toString();

    return x;
}

function translateSpecies (batString)
  {
    var text = batString;
    var result = text.replace(/ANPA/g, " Pallid bat");
    var result = result.replace(/COTO/g, " Townsend's big-eared bat");
    var result = result.replace(/EPFU/g, " Big brown bat");
    var result = result.replace(/LABL/g, " Red bat");
    var result = result.replace(/LACI/g, " Hoary bat");
    var result = result.replace(/LANO/g, " Silver-haired bat");
    var result = result.replace(/MYCA/g, " California myotis");
    var result = result.replace(/MYEV/g, " Long-eared myotis");
    var result = result.replace(/MYTH/g, " Fringed myotis");
    var result = result.replace(/MYVO/g, " Long-legged myotis");
    var result = result.replace(/MYYU/g, " Yuma myotis");
    var result = result.replace(/PAHE/g, " Canyon bat");
    var result = result.replace(/TABR/g, " Mexican free-tailed");
    var result = result.replace(/MYLU/g, " Little brown myotis");
    var result = result.replace(/MYCI/g, " Small-footed myotis");
    var result = result.replace(/NYMA/g, " Big free-tailed bat");
    var result = result.replace(/EUPE/g, " Western mastiff bat");
    var result = result.replace(/EUMA/g, " Spotted bat");
    var result = result.replace(/MY/g, " Myotis spp.");
    
    return result;
}

 

 

This might be a helpful references for you:

https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/b... 

Also, I didn't do this in my XLS form because I was just testing, but remember to set the bind::esri:fieldType to Null for all of these Javascript and display fields if you don't want these fields to be part of your feature layer attribute table. Also, the fields that are used in the calculations can have "hidden" set as the appearance type so they won't display in the survey. 

I really hope this helps! And if anyone else comes across this and has pointers, I'm all ears. I came up with this solution as a complete newbie to Javascript (~intermediate familiarity with Python) and referenced StackOverflow a lot...

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek

View solution in original post

8 Replies
Katie_Clark
MVP Regular Contributor

A couple questions - will you be able to use Javascript functions, or does the survey need to be public? (public surveys don't support Javascript functions)

And am I understanding correctly that these surveys will be submitted, and then accessed again through the inbox for additional data to be added by a new person? (hence why the summary note would be helpful)

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
mrosekulick
New Contributor III

The survey is not public, and it's currently published to our Portal. I don't have any experience personally with Javascript.

Yes, you are correct, we are using the inbox to re-access and add new surveys!

0 Kudos
Katie_Clark
MVP Regular Contributor

So, I had a bit of fun with this "challenge question" and wanted to find a solution, as I am very new to Javascript and wanted to take the opportunity to practice, while also hopefully help someone out. 

I got a solution to work 🙂  It's almost embarrassing to share since I *know* there are better methods out there and I'm probably not doing it in the most efficient or logical way, but....it works.

Katherine_Clark_0-1666285881459.png

If you're still needing a solution and want more details, let me know and I'm happy to share the XLS form. 

Best,

Katherine

 

 

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos
mrosekulick
New Contributor III

Amazing!! This solution is 100% better than my nonexistent solution. 🙂 I would love to see the XLS form!

0 Kudos
Katie_Clark
MVP Regular Contributor

I attached the XLS form, and here are the Javascript functions I embedded in the survey. 

 

function uniqueSpecies (translatedSpecies) 
  {
    var x = translatedSpecies
    x = Array.from(new Set(x.split(','))).toString();

    return x;
}

function translateSpecies (batString)
  {
    var text = batString;
    var result = text.replace(/ANPA/g, " Pallid bat");
    var result = result.replace(/COTO/g, " Townsend's big-eared bat");
    var result = result.replace(/EPFU/g, " Big brown bat");
    var result = result.replace(/LABL/g, " Red bat");
    var result = result.replace(/LACI/g, " Hoary bat");
    var result = result.replace(/LANO/g, " Silver-haired bat");
    var result = result.replace(/MYCA/g, " California myotis");
    var result = result.replace(/MYEV/g, " Long-eared myotis");
    var result = result.replace(/MYTH/g, " Fringed myotis");
    var result = result.replace(/MYVO/g, " Long-legged myotis");
    var result = result.replace(/MYYU/g, " Yuma myotis");
    var result = result.replace(/PAHE/g, " Canyon bat");
    var result = result.replace(/TABR/g, " Mexican free-tailed");
    var result = result.replace(/MYLU/g, " Little brown myotis");
    var result = result.replace(/MYCI/g, " Small-footed myotis");
    var result = result.replace(/NYMA/g, " Big free-tailed bat");
    var result = result.replace(/EUPE/g, " Western mastiff bat");
    var result = result.replace(/EUMA/g, " Spotted bat");
    var result = result.replace(/MY/g, " Myotis spp.");
    
    return result;
}

 

 

This might be a helpful references for you:

https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/b... 

Also, I didn't do this in my XLS form because I was just testing, but remember to set the bind::esri:fieldType to Null for all of these Javascript and display fields if you don't want these fields to be part of your feature layer attribute table. Also, the fields that are used in the calculations can have "hidden" set as the appearance type so they won't display in the survey. 

I really hope this helps! And if anyone else comes across this and has pointers, I'm all ears. I came up with this solution as a complete newbie to Javascript (~intermediate familiarity with Python) and referenced StackOverflow a lot...

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
mrosekulick
New Contributor III

I'm so excited to try this out! Thank you so much for your time and effort in this!

mrosekulick
New Contributor III

I just tried it, and it works like a charm! Thanks again! 🙂

0 Kudos
Katie_Clark
MVP Regular Contributor

oh, I'm so happy to hear that! Thanks for the follow up 🙂

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
0 Kudos