Select to view content in your preferred language

Consolidate attributes from 2 fields into one defined variable in Arcade AGO from Survey123 web

244
4
11-08-2024 11:03 AM
Labels (2)
Megan2
by
Occasional Contributor

In a nutshell, I created a Survey123 for requesting a certain permit. If the resident requests a start date between X and Y, their permit will be for 21 days. If they request a start date between Y and Z, their permit will end on June 1 specifically. Since in some cases the End Date is calculated based on the Start Date while in other situations it's a set rule of June 1, the only way I know to set that up in Survey123 is to have 3 questions, as laid out below.

Question1: Start Date (user can input any date within a given date range, set as a constraint)

Question2: End Date (visible only if Start Date is within a given date sub-range, set as a constraint) = Start Date + 21

Question3: End Date May (visible only if Start Date is within a different given date sub-range, set as a constraint) = June 1

Because the overall end date of the permit is therefore sometimes in one field and sometimes in the other, I'd really like to know if:

  • There is any work-around within Survey123 to build out constraints and calculations to meet both requirements. This would be especially useful since a staff member may need to adjust the start date in the resulting web map and therefore also update the end date, and it would be a heck of a lot easier for them if there weren't multiple "end date" fields.

OR

  • Define a variable in Arcade (in AGO for symbolizing) that consolidates the two into one, such as "if End Date is empty, put End Date May, else put End Date".

There will only ever be data in ONE of the two fields, not both, and never will they both be empty.

However, I can't find any documentation that mentions using IF or IsEmpty when defining a new variable. 

Ultimately, I am setting symbology colors based on the permit's approval status plus the dates. (Approved & In Progress, Approved & Future, Approved & Expired, Denied, and Under Review) I can work around all of this by just listing out all combinations individually with || for OR to check both end date fields but as mentioned before, if staff go in and update the dates, I don't want them to feel confused as to which field to mess with.

Pic below of the resulting data after filling out some pretend survey submissions.

2024-11-08_12-39-26.png

0 Kudos
4 Replies
ChristopherCounsell
MVP Regular Contributor

You could make both date questions null (don't submit any data) and then calculate one date question, hidden from the users? will work in survey123 and make things less confusing in ArcGIS online.

In the date calculation you can add an if statement to calculate the date, using the same logic you are using to show one of the two date questions.

  • User enters A or B in question 1
  • Question 2 or 3 appears based on A or B selected. They won't submit data.
  • Question 4 (hidden) calculates answer from 2 or 3, based on A or B selected.

This is in Survey123 Connect.

It will not work well if users are updating via survey (because null questions) but will if they update date in ArcGIS online 

Megan2
by
Occasional Contributor

Thanks for the suggestion! While I've dabbled a little in Connect (still very much a beginner), this survey has so far been made and managed in the web browser, and my understanding is that if I start editing the structure of the questions in Connect, that I will no longer be able to edit in browser, so I hadn't taken that step yet but certainly can if it would get me to the final structure I'm hoping for!

I also want to make sure I understand what you are suggesting - do you mind elaborating on the third bullet point? If this was a spreadsheet or Arcade, for example, it sounds like it would be structured as an IF statement, where:

  • If(Question2 = null/empty, put Question 3, otherwise put Question 2)
  • OR similarly
  • If(Question1 = A, put Question 2, otherwise put Question 3)

Can one do something like that in Connect?

0 Kudos
ChristopherCounsell
MVP Regular Contributor

if(condition, a, b)

But you'll need to nest them so it's 

if(condition, return a, else run second if)

If(${question1}='x',${question2}, if(${question1}='y',${question3},''))

Yes you'll be stuck with Connect after republishing.

The issue with my suggestions is that if you are using survey123 to edit, you'll have a bad time. You'll need to consider how the null fields and calculations play out when the survey form is opened a second time. This method only works well if they are using survey123 to submit data and updating the date value directly within the table (not survey form).

0 Kudos
Megan2
by
Occasional Contributor

Thanks, looking into which column this would belong in and whether I can use some form of is null or is empty as one of my conditions. Conceptually it makes sense but this is definitely beyond what I've done before in Survey123. I've made a copy of the survey so I can tinker with it without fear!

0 Kudos