Select to view content in your preferred language

Calculated fields display in Survey123 Connect form preview, but not ArcGIS Online feature service

5110
8
08-05-2020 10:51 AM
ColinDaniel
Occasional Contributor

I have a survey with numerous string fields (select one and select multiple questions) and want to create an integer field that provides a score based on what was entered into those string fields. In Survey123 Connect, I successfully set up conditional statements to assign these scores and the calculations appear to work correctly in the form preview. The calculations don't show up on my mobile device when I'm filling out the form, which is a little disappointing but from what I understand is just a limitation of using calculations in Survey123, but the REAL problem is that these calculations don't even show up in my ArcGIS Online feature layer after I've submitted (all other fields do). I have attached my XLS form and can share my hosted feature layer if that helps with problem-solving. Thanks! James Tedrick

8 Replies
by Anonymous User
Not applicable

Hi Colin,

Having a quick look at your survey, I think the problem is that you are combining text and integer fields and there may be a type mismatch. Select one and select multiple question types are text by default. If you want the app to behave like they are integer types, you need to set the bind::type to int. Similar if you want the field created in the feature layer to be integer, set the bind::esri:fieldtype to integer.

In you calculations in the following integer questions that use the text values from the select one question, you may need to also cast the values as integers, but wrapped the name with the int() property.

If all of this is configured correctly, you should see the calculated values appearing in the field app and web app, and in the Survey123 website and ArcGIS Online Data tab views for submitted records.

Hope this helps.

Regards,

Phil.

0 Kudos
ColinDaniel
Occasional Contributor

Hi Phil,

Thanks for the reply. I'm very much a novice with this, so I really appreciate your help. I tried your suggestions, but I still can't manage to get things to work.

If the select_one and select_multiple questions in my survey are strings, that's fine. All I want is the separate calculation fields (integer) to run a conditional statement on those select_one / select_multiple questions and, if that certain response was selected, to add a value to the field. So my calculation fields should only contain numbers, not a blend of string and number fields. The basic syntax I have looks like:

int(if(selected(${question}, 'abc'), 5, 0)) + int(if(selected(${question}, 'def'), 5, 0)) + ...

My calculation fields are set to integer type in both the survey and the hosted feature layer and in the survey, bind::esri:fieldType is set to esriFieldTypeInteger and bind::type is now set to int.

What else I tried: replaced the number function with int function in my calculation fields, removed quotations around the numbers in my calculations (e.g. they were '5' before where they are simply 5 now), used the coalesce function before the calculation, and tried to change the bind::type in the select_one and select_multiple questions to int (got an error message preventing me from converting the form).

I must still be missing something!

0 Kudos
by Anonymous User
Not applicable

Hi Colin,

Can you provide your updated xlsx file (you said you made more changes) so I can take another look?

Regards,

Phil.

0 Kudos
ColinDaniel
Occasional Contributor

Hi Phil,

Attached is my most updated version of the form. I kept tinkering with some of those things I had already mentioned above, but the calculations still do not show up in the form nor my ArcGIS online feature layer. Do I need to set the field type to calculate to get the calculations to work properly? At least for now, I would like to be able to view those calculated fields in the form, but the calculate field type automatically hides it.

Another thing that I thought of that could be part of my problem: I added the calculate questions to the survey AFTER populating the form with my ArcGIS Online feature layer, then went into ArcGIS Online and added the appropriate fields to match what was entered in the survey. It still publishes fine and they are both integer field types. Do I need to go back and re-create the form from a new feature layer?

0 Kudos
by Anonymous User
Not applicable

Hi Colin,

I used your latest form above (Grassland_Survey_v2.xlsx), removed the submission_url and published a new survey from Connect (which created a new feature service) and then tested the form in the field app.

I think the problem you are seeing is how you added the new fields to the feature layer and what type they were, based on how they are being used in the survey form. Note that calculate and hidden question types are text questions by default as per XLSForm spec, and are always hidden in the form and other data views. Using the esrifieldtype and bindtype columns on initial publish you can overcome the data type but not change the hidden property. You need to make sure everything matches in the form and feature layer. Sounds like something is not configured correctly and you are getting a mis-match between the survey form settings and the feature layer settings. Calculations will work in any field type (text, integer, decimal, date etc) provided the calculation you are doing matches the data type. Only use calculate and hidden question types if you do not want the user to see them at all, otherwise just use text, integer or decimal question types and put your calculation in the calculation column. You can also try using the new hidden appearance if you want to hide the question in the field app, but show it in the Survey123 website and data views.

As below, when I take you exact Grassland_Survey_v2.xlsx survey with no changes, and publish it, everything is working as I would expect and I can see the submitted data in AGO data tab and Survey123 website data tab.

Field app:

Survey123 website:

ArcGIS Online:

Hope this helps.

Regards,

Phil.

ColinDaniel
Occasional Contributor

Hi Phil,

Thanks for the help! Sure enough, I tried republishing it and got the results I wanted. Still not sure where the field mismatch was, but it probably didn't help that I tried to add the calculate fields in my feature layer after already creating the survey. Regardless, I'm so glad that it's working now. And I appreciate the details regarding calculate and hidden field types - that cleared it up for me. Really appreciate your help!

Colin

Sulettevan_der_Merwe
Emerging Contributor

Good day

Would like to know how to show hidden calculate in survey connect created form.

0 Kudos
Daniel_Perkins
Occasional Contributor

if you just need to view the result, try a note field. Or don't use the calculate type and use integer or decimal types and set them to read-only