Select to view content in your preferred language

Combining search function and pulldata function

489
8
a month ago
FarzanehAhmadikordasiyabi
Emerging Contributor

Hello friends,

The first question in my survey is email which is a text type question. In this survey I have some questions like name, phone number which are text and integer respectively. I also have two select_one list_name questions. Is it possible to autofill the name, phone number, and the two select_one department and select_one section questions based on the email if the clients submitted a request before? if not clients enter their information? I have a layer published in the portal that have all the request histories. I added pull data function but it is not working. 

Hey everyone,

I'm working on a survey and need some help figuring out how to streamline survey submission for clients.

The first question in my survey asks for the client's email address (it's a text type question). Further along, I collect their name (text), phone number (integer), department (select_one list_name), and section (another select_one list_name).

Ideally, I'd like the survey to automatically fill in the name, phone number, department, and section if a client has previously submitted a request using the same email address. If it's a new client, they would simply enter their information manually. I also have the list of the departments and sections in the choice sheet.

I have a layer in the portal that contains the history of all past requests. I've tried using the pull data function to achieve this autofill, but it's not working as expected. for the select_one department and sections can I use autocomplete search() in the appearance and pulldata function in the calculation?

0 Kudos
8 Replies
Neal-Kittelson
Frequent Contributor

Can you provide a sample of your xlsx with the pulldata calculation?  You are on the right track, sometimes the syntax is finicky.

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

Thanks @Neal-Kittelson  I fixed that issue, however I have another issues. I have a question named project_name and I set it to the select_one type. I want to set the survey so that it shows the names of the projects that clients submitted in their previous submissions and if their current project has the same name select one of them and if not write a new name. I used the same pulldata function and in the choice sheet I added the same name and label in the request history layer , which is the same as the survey field. But it is not working. It just shows the label of the field.

0 Kudos
TylerGraham2
Frequent Contributor

You're going to run into problems with search appearance to populate choice lists for existing users and a new user needing all department choices because if search appearance() doesn't find any matches you won't have any choices to select.  What I'd do is create 3 questions for each of those select_one questions. One would be for new users and give them all the choices.  The 2nd question would be for existing users and autofill their choice (You could even make it a read-only text field and then not even need the search appearance, just do a pulldata in the calculation field). Both of these would be set the bind::esri:fieldType column to null so it doesn't create these in your feature service. The 3rd field would be hidden and use a calculate to get the value from one of the first 2 fields and contain the data.  

One thing esri states is that pulldata isn't for populating choice lists.  For search appearance() to do what you are asking you will want to call the survey's feature layer as the tableName parameter. Give it a tableName that's unique from your other tables and CSVs, in my example below I'm giving it a table name of "userdept". 

search("userdept?url=https://myhostedfeatureserviceaddress", 'matches', 'emailaddress', ${emailaddress})

My example would search the myhostedfeatureserviceaddress layer's email address column for matches to the survey's ${emailaddress} field and populate the department choice list based on that. Make sure in the choices sheet you create a single row with the list_name and then set the name and label to the fields from the feature layer you want the values to come from.  So, in this example since we're pulling departments, I'd use my "department" field in the layer.

list_namenamelabel
deptListdepartmentdepartment

 

Here's some more on the search appearance()

https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformsappearance.htm#ESRI_SECTION1_46A7...

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

Hi @TylerGraham2 , for the name, phone number, department, and section name i used just pulldata function and it works. Some of the departments do not have sections and the section field is required. How can I set it so that  the section question is shown only if the selected department has a section? Also, I have problem with project name question. I wanna my survey list the clients' previous project's names from their previous submissions and if it is the first time submitting a request or their current project has a different name they be able to write it's name. Is it possible? If yes, how? 

0 Kudos
TylerGraham2
Frequent Contributor

For the Section question use the relevant column and use selected(${questionname}, 'value'}) function where the value is the department you want the question to appear. To get it to appear for several values use the "or" operator and repeat the selected() function.  selected(${question1}, 'A') or selected(${question1}, 'C') in the relevant column will make the question visible if on question1 someone selected A or C, and it will hide the question if another choice was selected in question1.  

Are you just trying to show them a list of project names they've previously submitted? Do they need to interact with it, or just see the list?

 

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

There are more than 30 departments , it will be hard to use or operator. Actually there are just 2 departments that do not have any sections. How can I just set so that section doesn't show just for those two?

0 Kudos
TylerGraham2
Frequent Contributor

You might try not(selected(${question1}, 'A')) or not(selected(${question1}, 'B')) in the section relevant column for those 2 departments without sections to hide when they are selected and show when they're not. 

If that doesn't work, sometimes you just have to brute force the approach to get Survey123 to do what you want and you might have to use 30 or statements. I usually copy/paste each and/or section and once I've got all the ones I need, I then copy/paste the values I want from the choice list in.  It goes faster than typing it all out over and over.  

0 Kudos
FarzanehAhmadikordasiyabi
Emerging Contributor

@TylerGraham2 thanks for your help! For the project's name I want to select the name, if the current request's project's name is the same as their previous submission , they just select instead of writing it. It actually happen frequently. most of our clients have like 5 or 6 types of project(project names) and the difference is their locations.

0 Kudos