Select to view content in your preferred language

Report Templates: Printing a section ONLY IF the answer begins with two particular characters...

256
6
10-09-2024 02:10 AM
Bio_GIS
Emerging Contributor

Hey all, I am attempting to create a report template for a biological firm, and I need to conditionally print some sections of the report and then conditionally populate said sections with particular answer values based on the first two characters in the answer. This is the only way data was collected, and I am hoping to be able to parse each answer string and print it under a heading related to that answer's taxonomical classification based on the presence of a substring. I'll give a specific example below. At this point, I'd even be willing to brute force this by listing a conditional for each answer...would rather not get to that point.

 

The gist of it:

So, the data is basically a massive list of non-target species observations that the biologists observed while in the field. The data is as follows, with an example from each classification:

 

(AAFCF+) Xenopus laevis, (AAFCF+) African clawed frog

(BCAGU ) Larus californicus, (BCAGU ) California gull

(IBOVA ) Bombus vandykei, (IBOVA ) Van Dyke bumble bee 

(MBOBC ) Lynx rufus, (MBOBC ) Bobcat 

(RDEIG ) Dipsosaurus dorsalis, (RDEIG ) Desert iguana

 

Where: the first letter of the animal's alpha code (in the parentheses) is the classification of the animal, which is corresponds to amphibian, bird, insect, mammal, and reptile, respectively. This is all the data we have for each entry, which brings me to my main issue...

What I need to do is take each of these data points and place them in a table. That's easy enough of course, but what is ACTUALLY needed is a table that has the sightings broken down into their respective type classification. Under each type classification heading, I need to print only those animals within that classification. I also need the headings for each section (amphibian, bird, etc.) to only print when there was a sighting of a species within that classification. And finally, I'd love to print the both the scientific and common name of each species as I've described above, only I'd like to remove the parentheses and the contained alpha code. Here's an example of the final output, along with some template code that I've placed in there for my own benefit during this process. (NOTE: I know that the template will need many, more loops than the one I've got here, this is not my working draft.)

 

${#wildlife_observations}${wildlife_other}

Scientific Name

Common Name

Reptiles

${wildlife_observed | getValue:""}

${wildlife_observed}

Amphibians

Anaxyrus boreas

Western toad

Birds

Aquila chrysaetos*

Golden eagle

Insects

Zenaida macroura

Mourning dove

Mammals

Sylvilagus audubonii

Desert cottontail

${/}

         *Denotes special-status species

 

So, there you have it. Can anyone think of a solution to this? Is there a way to grab individual characters in a string on the fly in a template? Or to check a string for the presence of a substring? Will I be able to conditionally print headings but then loop over the records and populate the sections?

 

Final note...I figured I should outline my current plan, which is as follows: conditionally print the headings based on the presence of a species in said classification, triggered by the first record that the report generator comes across. I will of course figure out if the record exists by searching each data point in this question for "(A", "(B", "I", "(M", and "(R". Then, I will either loop through ALL of the answers again, only printing the ones that contain the "(X" for said section, or I will just print until I come across the next "(X" in the progression. Thankfully, the domain list is grouped alphabetically so either should work. I think that this logic will work just fine, I just need some help with the syntax to get me there.

 

Thank you all for your help!!

0 Kudos
6 Replies
DuncanC
Frequent Contributor

I think the best option will be to do some preprocessing in Survey123 to be ready to use the print template.  I wish the templates had way more scripting/logic operators, they are very limited.  I'd add a field, do your check for the first characters and save a flag to it that will determine if that row is to be printed in the output.  Same for headings.  I'd add the logic to the form and just have a field you look to on the template side for a yes/no print that header.

It's still only going to mostly work, Survey123 is just riddled with bugs.  These calculations will work most of the time, but just be randomly skipped sometimes.  My actual solution would be to collect the data, then have a python script come through and do what needs to be done, either directly creating the output or populating a records that gets fed into the print template engine to create the output.

0 Kudos
Bio_GIS
Emerging Contributor

I'm at the point where I think I'm just going to code it. It's a bit of an ask for the capabilities of the Survey123 templates, and I can write code, so it's just begging for me to create a GUI front-end for the biologists to print what they need from the data.

0 Kudos
abureaux
MVP Frequent Contributor

I need to conditionally print some sections of the report

IF can be used on its own in feature reports to test is something contains data.

E.g.,
${if username}${username}${/}

This will only print ${username} if ${username} contains data. You can also add carriage returns within that IF statement to aid in formatting.

And finally, I'd love to print the both the scientific and common name of each species as I've described above, only I'd like to remove the parentheses and the contained alpha code.

By the sound of it, you need to collect data differently. All this data needs to be added to a CSV, and each column of that CSV should contain specific data (e.g., scientific name, common name, etc.). Then, when a selection is made, you use calculates to pull all those columns as separate items.

Under each type classification heading, I need to print only those animals within that classification

Something like this could work. Color coded for clarity.

${#wildlife_observations}${if wildlife_observed=="A"}${wildlife_observed}${/}${/}

I also need the headings for each section (amphibian, bird, etc.) to only print when there was a sighting of a species within that classification

I don't know what your data looks like, so I modelled this after how I would expect me to have set this up. But here is an example to hopefully point you in the correct direction.

abureaux_1-1728507906826.png

For a little clarification, I would have a field outside the repeat (e.g., ${cnt_r}) that counts every time a specific species was sighted. That way, I would easily know if any birds were sighted, for example.

 

There is a lot going on there, and without looking at the DOCX or XLSX, it's hard to know exactly what the answer is. But hopefully this is enough for you to resolve at least one or two items for now.

0 Kudos
Bio_GIS
Emerging Contributor

Thank you for your reply, I see a few techniques in there that merit some exploration. I have a couple clarifications, however, and can swing the domain list file and my current template your way if you'd be interested. Currently, every species is in a domain list CSV file that is formatted exactly how I wrote it in my post:

(AAFCF+) Xenopus laevis, (AAFCF+) African clawed frog

Due to this formatting and the fact that nothing else was gathered along with the species sighting data point to indicate type of animal, the only way I have of determining the classification is that first letter within the parentheses. I don't know if your formatting would work in the syntax you gave due to the open parenthesis at the start of the string:

${if wildlife_observed=="A"}

Can you suggest a way around this? I am concerned I may be beyond the capabilities of Survey123 report templates at this point. It'd be very simple to code, as I'm sure you know, and that's just driving me a bit nuts haha. Any and all help you can offer would be very much appreciated. Thank you again for your time!

0 Kudos
abureaux
MVP Frequent Contributor

Unfortunately, there is nothing like left() the reporting template that can extract data like what you would need.

I would suggest you 1) update your CSV and survey to collect data in the desired format, and 2) look at using FME or ArcPro to post-process the previously collected data to be in the same proper format.

0 Kudos
Bio_GIS
Emerging Contributor

Yep, heard and heard. Thank you a bunch for your help!!!

0 Kudos