pulldata() and select_multiple data relationships

1018
5
Jump to solution
03-16-2022 08:10 AM
AlexBakhtin
New Contributor III

Hello everyone,

I am currently working on a form where I am utilizing pulldata() and select_multiple in tandem to pre-populate information into a different select_multiple field. My main question is:

Is it possible to have a select_multiple question dynamically select choices in a different select_multiple? I attached an example to this post where I'm using fruits and would like to have the colors automatically populate based on the selected fruits. Ideally I would like to utilize pulldata() as I can autogenerate the comma separated strings I need to automatically select the select_multiple choices from pulldata() but I would like to see what is possible with this setup. From my testing, I'm not able to reliably have all of the colors populate based on the selected fruits.

Alex Bakhtin
0 Kudos
1 Solution

Accepted Solutions
AlexBakhtin
New Contributor III

For anyone interested, I figured out an acceptable workaround if anyone finds themselves in a situation where they need to auto-populate a select_multiple based on what was selected in a previous select_multiple question. I got the overall idea of how to do this from the Repeats documentation

  1. Create a repeat that has a max repeat count of selected items in the first select_multiple using count-selected()
  2. Inside of the repeat, use selected-at(${question_name}, pos(..)-1) to get each individual item selected into its own repeat.
  3. Use pulldata() to get associated attributes of each selected item
  4. Outside of the repeat, use join() to concatenate all attributes into a comma separated value
  5. Remove duplicate entries in the comma separated value (otherwise when you go to submit it will fail). I wrote a function to accomplish this in Javascript:

 

 

function dupeclear(ppe_formatted_text) {

    var x = ppe_formatted_text.toString();
    x = Array.from(new Set(x.split(',')));
    return x;
}​

 

6. Use the cleaned up concatenated value as a calculation for the second select_multiple.

Please note that the only downside to this method is that you need to cycle through each repeat manually to get the text field outside of the repeat to pull each value in. Once I figure out how to do that through a calculation (if possible) I will update the post.

I probably didn't do the best job in writing this out so I'm also attaching the final sample workflow along with some notes in the hints of each field to this post.

 

Alex Bakhtin

View solution in original post

0 Kudos
5 Replies
BryndaHatch
Esri Contributor

I have a similar project where I am filtering the list of counties based on the state chosen.  I am not using pulldata().  In the choice_filter column of the .xlsx form, on the row asking for the county, I have a filter set looking at what was selected in the state field.  I have a separate .csv file stored in the media folder that lists the counties and the states they are in.  The filter looks for what counties have the state matching what the user entered for the state in the previous question.

Hope this helps.

0 Kudos
AlexBakhtin
New Contributor III

Would you be able to please share a small snippet on how that setup looks? I think that can theoretically work for me as long as I can get things to auto-select as well within that select_multiple which would be based on a previous select_multiple question.

Thanks!

Alex Bakhtin
0 Kudos
BryndaHatch
Esri Contributor

this is from the .xls form

BryndaHatch_0-1647452674241.png

this is from the choices-boundaries02-counties.csv in the media folder

BryndaHatch_1-1647452766662.png

 

0 Kudos
AlexBakhtin
New Contributor III

Ah understood - I am familiar with working with cascading selects like that however I'm wondering if it is possible to preform a calculation that would automatically select options in a select_multiple based on what you select on a previous select_multiple question?

I attached a quick video but in short, is it possible to have all of the food colors selected when all of the foods above are selected? With the way I have things set up currently, I can't seem to get it to work the way I would like.

The actual calculation is happening from a pulldata() function:

pulldata('color_csv', 'food_color', 'food_name', ${food_name})

And the color_csv file contains the following contents:

food_namefood_color
applered
peargreen
orangeyellow,orange
Alex Bakhtin
0 Kudos
AlexBakhtin
New Contributor III

For anyone interested, I figured out an acceptable workaround if anyone finds themselves in a situation where they need to auto-populate a select_multiple based on what was selected in a previous select_multiple question. I got the overall idea of how to do this from the Repeats documentation

  1. Create a repeat that has a max repeat count of selected items in the first select_multiple using count-selected()
  2. Inside of the repeat, use selected-at(${question_name}, pos(..)-1) to get each individual item selected into its own repeat.
  3. Use pulldata() to get associated attributes of each selected item
  4. Outside of the repeat, use join() to concatenate all attributes into a comma separated value
  5. Remove duplicate entries in the comma separated value (otherwise when you go to submit it will fail). I wrote a function to accomplish this in Javascript:

 

 

function dupeclear(ppe_formatted_text) {

    var x = ppe_formatted_text.toString();
    x = Array.from(new Set(x.split(',')));
    return x;
}​

 

6. Use the cleaned up concatenated value as a calculation for the second select_multiple.

Please note that the only downside to this method is that you need to cycle through each repeat manually to get the text field outside of the repeat to pull each value in. Once I figure out how to do that through a calculation (if possible) I will update the post.

I probably didn't do the best job in writing this out so I'm also attaching the final sample workflow along with some notes in the hints of each field to this post.

 

Alex Bakhtin
0 Kudos