Survey123 Tricks of the Trade: hidden, relevant and body::esri:visible

24803
34
04-19-2022 02:12 PM
IsmaelChivite
Esri Notable Contributor
11 34 24.8K

 

There are many ways to hide questions using XLSForm. How you do it depends on a few things. In this blog post we will review some common scenarios, common problems and best practices. Familiarity with Survey123 Connect and XLSForm is assumed.

Calculate a question and hide it permanently using the hidden appearance

The most common scenario for permanently hiding a question is where you want to automatically calculate a value and keep it hidden from users.  Below is an example where I calculate the horizontal accuracy of a geopoint question and the email of the currently signed-in user. In both cases I use an expression in the calculation column and set the appearance of the question to hidden.

IsmaelChivite_0-1650396356099.png

Calculate and hidden question types versus hidden appearance

In the example above, one could argue that the same could have been achieved using a calculate or hidden question types. For example:

IsmaelChivite_1-1650396736427.png

The calculate and hidden question types are both part of the XLSForm specification and as such supported in Survey123. Having said this, I think it is better to use the hidden appearance.

The problem with the calculate and hidden question types is that they allow you to hide a question at the expense of giving up the question type. Look at row 3 above, for example: If I set the question type to hidden, my question type is no longer decimal. It becomes a hidden question type, which automatically maps to a string (text) data type. Calculate and hidden question types always default to text. That is a problem, because my accuracy calculation is going to output a decimal value and I do not want it as text. To correct this, I need to go into the bind::esri:fieldType column and specify that the field type is esriFieldTypeDouble. That is one more thing I need to worry about! I would rather set my question type as I like, and then use the hidden appearance.

The only case where I still like to use calculate question types is when working with grid layouts. In that case, calculate has the advantage that it does not take up any space in the grid layout, as opposed to a question with the hidden appearance, which will still take a space (albeit an empty space).

Permanently hiding a question to keep track of status

Let's explore another scenario where you want to permanently hide a question, and use the hidden appearance. Pretend you are creating a form for people to report incidents. You want to use a field to keep track of the status of the incident. When an incident is reported with Survey123, you want the status to always be 'Open'. Using a second survey, or maybe another ArcGIS app, you want another person to open the record and be able to change the status to 'In progress' or 'Closed' using a drop-down list.

This is one way to do it:

IsmaelChivite_3-1650400003654.png

Note that rows 2 and 3 will be visible to the user, but rows 5 and 6 will be hidden. In row 5 we store the status, which has a default value of Open. The respondent of the form will not see the question, but when the record is submitted, the status field will always be Open. The status question uses the select_one question type. This means that when the survey is published, a domain will be created so values can be changed through a drop-down list.

This is an example where the hidden appearance has saved our bacon again! If we were to use a hidden question type in row 5, we could have not had this question create a domain. Row 6 has no secrets: We add it so the survey layer has a field where a reviewer can enter comments. This question is hidden in the form but visible to any ArcGIS app that opens the layer.

Using a hidden question to initialize a form

Another common scenario where you want to hide a question is when you prepopulate a value when the form is initialized using app link or a custom URL. Here is an example:

IsmaelChivite_0-1650398693627.png

Note that in this scenario, the hidden question is not being calculated. Instead, it is expected that you populate this question when the form is initialized through a custom URL parameter or app link. You pass the customer ID to the form, and then the customer name, surname and phone questions are automatically populated. Again, you may want to hide the customer ID question to avoid confusion: You expect the name, surname and phone to be known, so you present them to the respondent in case they need to be corrected. As for the customer ID, you do not want anyone to change it and you want to keep the form simple, so you hide it.

You do not always need to hide a question when it receives data from an app link, but if you want to hide it, this is the best way to do it: with the hidden appearance.

Dynamically hiding questions using body::esri:visible and relevant

While permanently hiding a question is useful, you might also want to show and hide a question dynamically.  There are two main ways to do this in Survey123. These two approaches have subtle, but important differences.

The body::esri:visible column dictates if a question is visible or not.  If the expression in this column evaluates to false, the question is hidden. For example:

IsmaelChivite_4-1650400579621.png

In the above design, the comments question in row 4 will only be visible if the damage level is High. There is not much more to it: body::esri:visible controls the visibility of a question through an XLSForm expression. That's it!

We also have the relevant column which does something similar, and more. The relevant column, like body::esri:visible, controls the visibility of a question, but it also clears the value in the question when the expression evaluates to false. Big difference! Visible and relevant are two very different things!

The relevant column affects both the question's visibility AND its value. This can be both very useful and also sometimes problematic. For example, say a question is relevant and the user answers it. Now the user changes something in the form that makes that question not relevant. At that point, whatever value was entered in the question is cleared. That data is lost forever. This is often known as question skipping, which is different to simply controlling the visibility of a question.

A lot of survey authors use the relevant column over body::esri:visible. In part, this is due to history: We added support for relevant many years ago. The body::esri:visible column is much newer. Now that you have the choice, you can decide what behavior you want.

Now, something important to remember is that image and audio questions do not support body::esri:visible.

Use groups to avoid repetitive relevancy and visibility expressions

When working on very large forms, you may find yourself applying the same relevancy or visibility expression to many questions. When this happens, consider using groups so your expression can be applied once to the group, rather than to every question. For example, consider this situation:

IsmaelChivite_1-1650402004931.png

See how many times the expression ${building_affected} = 'Yes' needs to be evaluated? 11! Next, have a look at this:

IsmaelChivite_2-1650402118498.png

In this case the visibility expression is evaluated only once, which is much more efficient. You do no have to use this technique every time you see two or three consecutive questions using the same visibility or relevancy expression, but keep it in mind, particularly when your form grows in size.

 

34 Comments
AnthonyJonesRSK
Frequent Contributor

Hi Ismael,

Thanks for the great article. I'm one of those people that always used the relevant column and was frustrated by the way it would delete the data when someone went back and changed something (often by accident, particularly when working in the inbox), therefore losing all their data. The body::esri:visible option is a fantastic addition that will help avoid this going forward.

However, I think I may have stumbled across a bit of a bug with it. I've used this option for a web form created in Connect and have noticed that the calculation in the body::esri:visible column is ignored when applied to a page (N.B. It works fine in Connect). In my case I ended up with the below where the page still shows but no questions are available. I've noticed that if I revert back to using the relevant column with the same calculation then the problem no longer occurs. Is this something that can be looked into please?

AnthonyJones5_0-1655891754019.png

Thanks

Anthony

JessicaJThompson
Frequent Contributor

Hello @IsmaelChivite and All!  

Thank you for laying this out. 

I may have missed an explanation in the documentation. I am looking to solve a puzzle.

I am wondering if and how a default/calculated value could be applied for a question only when it is not visible. (Using Survey123 connect Version 3.14.274)

I do not like there to be no-values/blanks in my data if possible. If a question isn't relevant to the specific location -

1) I would like it to not be visible to the surveyor, and I want the data to reflect that with a default of something like "not relevant to location".

2) I do not want this default/calculation to occur if the question is visible.

3) I do not want this to be an option in the choices list. Because when the question is visible the "not relevant to location" does not apply. 

Does it seem correct to put a conditional if(selected(${PUMP_STATION},'GWINNETT STREET')'Not Applicable to Location', '') in the default column? This seems flawed. 

Thank you again in advance!

Jessica

cole_KTB
Occasional Contributor

Thanks for this super helpful article! I was wondering how I might use the body::visible column in the way you spoke of to display a conditional question when one option from a "Select_multiple" or all that apply type question. I would like this hidden question to display when option X is selected regardless of if it is selected alone or accompanied by other options. 

IsmaelChivite
Esri Notable Contributor

@cole_KTB Thanks! You will want to use the selected() function. Check the selected(question,value) section in this blog: https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-xlsform-functions/... 

cole_KTB
Occasional Contributor

Thank you @IsmaelChivite . Funnily enough I discovered this article and implemented exactly that right before your reply! 

Murage
by
Occasional Contributor

Hi @IsmaelChivite ,

We have used relevant before to hide groups that were not relevant and this resulted in deleting of the data when used to edit data from the inbox. We have now opted to use body::esri:visible option, however, it appears to have a similar bug to what @AnthonyJonesRSK  has mentioned in his post above.

 

Any group that is not visible still shows up when using pages in the webform but with no questions similar to the screenshot Anthony provided. This presents a confusing user experience moving through blank pages. Has there been any new progress on it?

RubenImanolRiveraSaavedra
New Explorer
Hello, I have a question, if I wanted to manipulate my csv file to be able to create a new prefill, could I do it from the survey123 form?
JerrySneary
Regular Contributor

Hi @IsmaelChivite ,

Can you hide a group in a public survey if they don't have an AGOL login?

Kind regards,

Jerry

IsmaelChivite
Esri Notable Contributor

@JerrySneary  You should be able to. Expressions in the relevant and body::visible columns should work regardless. 

BrandonA_CDPH
Frequent Contributor

@IsmaelChivite  and @JerrySneary  - I have a slight variation on this theme. Is it possible to make a question/group visible dependent on whether they have a AGOL login or not. Thinking of somehting like this: - If they are an internal user (and have a login), record name and email automatically - if they are an external user (not logged in), ask for name and email.

PS I really appreciate when these posts get the juices flowing about how I can make forms better. Thanks @JerrySneary for giving me inspiration.

IsmaelChivite
Esri Notable Contributor

 

@BrandonA_CDPH  I guess something like this should do:

IsmaelChivite_1-1683042918435.png

If the user is logged-in, the name and email questions will get automatically populated and hidden. If the user is not logged-in, they will show in the form for the end user to complete.  In this particular case, you will not want to use the relevant column. You will want to use the body::esri:visible column instead.

 

BrandonA_CDPH
Frequent Contributor

@IsmaelChivite - that's a great solution. Thank you so much! 🙂

JerrySneary
Regular Contributor

@IsmaelChivite 

You're welcome @BrandonA_CDPH .

In my case, I have a form that is going out to the public. I want to create a group of questions that are hidden to the public, or only relevant if the person using the form has logged in. I've searched for the syntax to do this but have come up short.

@IsmaelChivite can you point me in the direction of an example of the syntax?

RubenImanolRiveraSaavedra
New Explorer

Hi @IsmaelChivite, I have a question, if I wanted to manipulate my csv file to be able to create a new prefill, could I do it from the survey123 form?

Adam_Inglis
Occasional Contributor

@IsmaelChivite 

Great article, thanks very much, it solved half my problem.  Do you know if image questions will support body::esri:visible in the future?

LeahClark
Occasional Contributor

Great info @IsmaelChivite - but I am struggling with the same issue as @AnthonyJonesRSK and @Murage where the question still appears in the survey when opened in browser... Is there a solution to this?

IsmaelChivite
Esri Notable Contributor

@ZhifangWang : I am not sure if this problem is in our radar: body::esri:visible ignored by pages in the web app. See comments above.

ZhifangWang
Esri Regular Contributor

Hi @LeahClark ,

The issue you mentioned can be referred "BUG-000155815 Empty pages appear when a group with a field-list appearance has a body::esri:visible expression that equates to false when using the ArcGIS Survey123 web app.", and it has been fixed since the 3.17 version of the web app.

Can you please confirm your survey was published in a version of Survery123 Connect >=3.17 version? If not, you can test the fix by appending "?version=latest" to your survey. Once satisfied, republish your survey using the latest 3.18 version of Survey123 Connect.

 

Thanks,

Zhifang

mldewing
Occasional Explorer

@IsmaelChivite - Thank you for the helpful article! The "Tricks of the Trade" series has been a lifesaver for me these past few months.

Recently, I've noticed some weird behavior with the relevant column and I'm looking for workarounds. Perhaps you can offer some insight?

The issue involves fields with relevant conditions not clearing if the condition is no longer met. For example, a user answers Question #1 'Yes' and then populates Questions #2 and #3. If they change the answer to Question #1, the answers for #2 and #3 are not cleared on the backend. In addition, this error only seems to occur in the published environment; the functionality works as intended and clears the fields when previewing with Survey123 Connect. This difference in behavior leads me to think this may be a bug, but perhaps it's user error. Do you have any ideas on how to automatically clear these fields outside of using the relevant column?

LeahClark
Occasional Contributor

@ZhifangWang Thank you! I was able to solve this by downloading and installing the newest s123 version. I was using the s123 from the Microsoft store (which says it is updated automatically) but it was running version 3.12, and I couldn't find a way to manually update the Microsoft store one. Instead I manually downloaded and installed and that got me to the newest version which fixed the issue I was seeing. Thank you for your response!

PaulPetersen1
Frequent Contributor

@mldewing , I am having the same issue in the web app, running in Edit mode. If I have data entered in questions with Relevant logic applied, if the relevant becomes false and then I submit the form, the non-relevant data fields are not cleared or nullified in the database. Works fine in Connect, but not in the web form. Did you ever figure this out?

DianaTorres10
Occasional Contributor

Hello @IsmaelChivite 

I was wondering if you can use the selected() function with multiple options in the body::esri::visible column.

I'm triying to make a question appear when the user selects one option from a designated list in a previous question.

Right now I made it work with just one option.

Thank you!

DougBrowning
MVP Esteemed Contributor

@DianaTorres10 You can use or.  selected() or selected() or ...

DianaTorres10
Occasional Contributor

@DougBrowning Thank you so much! It worked.

KateSherman_psmfc
Emerging Contributor

Hello @IsmaelChivite,

I've found that in the web-form and within a nested repeat, the body::esri::visible works only if the selection is made in the first repeat, not subsequent repeats. Have you seen this behavior? 

For example, I have a nested repeat to select organizations involved in a project. I wanted to use body::esri::visible and have a field appear if the project organization is a tribe. This works if someone selects the tribal organization as the first organization in the nested repeat. However, if it is any other selection, than it does not appear.

Do you have any suggestions for this behavior?

 

Nicholas_Leitgeb
Occasional Explorer

Hi there!

I'm trying to design a survey where question 2 will only pop up if certain answers are given in question 1. Question 1 has 3 answers: A, B, and C. I want question 2 to pop up if answers A or B are given, but not C.

Is there a way to do that in the body::esri:visable column?

I tried selected({$question_1}='A') and selected({$question_1}='B') and I tried selected({$question_1}='A') or selected({$question_1}='B')

Any other thoughts? Any help would be greatly apricated!

Thanks,

Nick

abureaux
MVP Frequent Contributor

@Nicholas_Leitgeb Your selected() is wrong. Try:

selected({$question_1},'A') and selected({$question_1},'B')

Nicholas_Leitgeb
Occasional Explorer

Ah ha! The coma instead of the = did the trick!

The expression that worked was: selected(${question_1},'A') or selected(${question_1},'B')

Thank you for the help @abureaux 

JenMcRuer
Regular Contributor

I know this isn’t exactly what I’m asking… but perhaps similar.

 

I am creating a survey that intentionally asks for participants’ names. Later in the survey I am asking personally identifying information like age and gender. Is there a way to ask this subset of questions such that the data comes back disassociated with the names? Or does it have to be a separate (anonymous) survey? 
thank you

SIG-EscutismoCNE
Emerging Contributor

Good afternoon,

Is it possible to only show the field if not null?

Thank you for your attention

ShariF
by
Regular Contributor

Is it possible to hide the submit button based on body::esri:visible and relevant?

abureaux
MVP Frequent Contributor

@ShariFNo. That is a part of the larger UI.

You can of course use the "required" field to prevent submissions until a condition is met though.

ZhifangWang
Esri Regular Contributor

@SIG-EscutismoCNE ,

To only show a field if not null, you can use the string-length() formula. For example, in the relevant or body::esri:visible of the target question, use string-length(${question_one})>0 will only show the target question if question_one is not null. You can also replace question_one with the current question name or a dot "." (represents the current question) too.

ZhifangWang
Esri Regular Contributor

Hi @ShariF ,

If you are using the Survey123 web app, for customized form elements, including the Submit button, you can use hidden appearance to hide them. In addition, you can use ?hide=submit URL parameter to hide the Submit button.

The Submit button cannot be hidden by body::esri:visible column currently. Like abureaux mentioned, you can set the required column of a (hidden) question to prevent from submitting the survey.

Would you mind sharing your use case that requires hiding the Submit button by using an expression?