Default value for a select_one question type

1408
9
12-07-2018 12:00 PM
Highlighted
Occasional Contributor II

Can you take a value from a select_one question list and set one of those values as the default answer to that question? I feel like I have done this before but it is not working in my current survey. I must be putting this in wrong. 

       Expl: Choices are Small, Medium, Large, and I want my question to default the answer as "Small" 

Tags (2)
Reply
0 Kudos
9 Replies
Highlighted
Esri Regular Contributor

Hi Adam, the default value for a select_one can be entered in the default column in your XLSForm. In your example, enter "Small" (without quotes). Please see Prepopulate answers—Survey123 for ArcGIS | ArcGIS for more info.

Jim

Reply
0 Kudos
Highlighted
Occasional Contributor II

Thanks Jim for the answer,

I wanted to confirm there wasn't something else I was missing. That is exactly what I tried (also tried with quotes when that didn't work), but the default values are not appearing in Survey Connect testing, or after publishing and downloading my survey. No default field values set for any select_one questions are coming through. 

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Adam, could you please provide the XLSForm for your survey so I can test? Thanks, Jim

Reply
0 Kudos
Highlighted
Occasional Contributor II

Jim,

Please see the attached file. I was trying to set fields "vision_light" to default "none", kickplate to default "small", bumper to "No", and thickness to "1.75"

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Adam, thanks very much for the XLSForm and other survey files. At a quick glance it looks like the pulldata calculation could be superseding the default. I'll take a look and report back.

Jim

Reply
0 Kudos
Highlighted
Occasional Contributor II

Thanks Jim,

That is probably what is happening. I didn't think of that because those fields really don't have much data in the dataset to pull from, but I know the pulldata & select_one functions don't play well together so it is likely it won't work with defaults either. Thanks for looking into it. 

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Adam

Just confirming: a default is applied when the survey form first loads or, if in a repeat, when a repeat record is added; a calculation is applied when the values it relies on change. In this case asset_tag is calculated, which in turn applies the calculations for vision_light, kickplate, etc. (overwriting their defaults).

One suggestion would be to modify each calculation so that it results in a default value if the asset_tag is null. For example:

if(${asset_tag}='','Small',pulldata('features','kick_plate', 'asset_tag', ${asset_tag}))

Setting a default for 'thickness' in the default column should work as normal as this question does not have a calculation.

Jim

Reply
0 Kudos
Highlighted
Occasional Contributor II

Jim,

The problem with adding an if statement is there is no field I can use for that to work properly. For example, all of my features have asset_tag values, thus eliminating the default "Small" to ever appear in my kickplate field.

I could use another field to return null, thus making the default "Small" to appear, but then that voids my pulldata function. I end up overwriting existing data I want to keep with inaccurate default data (asset_tag=null so kickplate = Small, but my table shows kickplate = Medium for that feature). The work around is to use 2 fields, 1 text field "kickplate1" using pulldata, and 1 select_one field "kickplate2", only relevant and with default values if "kickplate1" is null. The obvious problem here is having to create 2 fields for capturing each attribute.

What I really need to be able to do is say IF "my pulldata function" = null, then activate the default value. And to go 1 step further, to have that statement in a select_one field type. By default, my pulldata functions are already void in any select_one fields. So select_one overwrites pulldata, and pulldata voids default values. So it appears here that my best option is just to eliminate the calculation completely. 

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Adam

Apologies, I misread your workflow; the thinking was the if statement could be used to set a default for a new asset, i.e. one that doesn't have an existing asset_tag and isn't already in the CSV. I now appreciate this isn't particularly useful in this survey!

Regarding this workaround...

The work around is to use 2 fields, 1 text field "kickplate1" using pulldata, and 1 select_one field "kickplate2", only relevant and with default values if "kickplate1" is null. The obvious problem here is having to create 2 fields for capturing each attribute.

...to assist with this, you could use a calculate question with a null field type (as I see you've already used for several other questions). This would omit the question from the feature service, so you're not storing superfluous data. As you've suggested, put a pulldata in the calculate question. Then use an if statement for the select_one, e.g. if(${calc_kickplate}='','Small',${calc_kickplate}). Providing the values in the CSV exactly match the choices for the corresponding select_one, the correct value will be selected in the form. The user can then modify this selection if required.

Alternatively, would it be feasible to add the default values into the CSV, for all door records that have empty values? Then you could use the pulldata on its own.