Select to view content in your preferred language

PullData AGOL Layer AutoPopulate Field

4885
10
Jump to solution
09-12-2023 10:56 AM
ModernElectric
Frequent Contributor

I am beyond frustrated with this even after all the research and and tutorials I have been reviewing and nothing is working. This should be a very simple concept and I am missing something.

Attachment: Enter Inventory Number - The user is to enter the company inventory number (lets say 1050). From there, I would like it to automatically populate the field (Modern's Inventory Description).

I have a hosted feature layer on AGOL that has the Inventory Number and Description.

In the calculation: pulldata("@layer", "getValueAt", "attributes.DESCRIPTION", "PATH TO AGOL", ${Inventory})

However, when I enter 1050 into the survey, the Inventory Description remains blank. 

Please help since I am really lost here.

Thank You

 

0 Kudos
1 Solution

Accepted Solutions
Vinzafy
Frequent Contributor

Hey there,

I got this to work! A few notes:

  • getRecordAt/getValueAt are spatial queries. Since you're essentially doing an aspatial table lookup, you should be using getRecord/getValue.
  • getRecord would return the entire JSON which you can then pull from. For example, if there were numerous fields that you want to get data from, you can use getRecord to pull the entire JSON, then use pulldata("@json"...) to pull from that as opposed to making numerous queries on the feature layer.
  • Since you only want to return one attribute, you can use getValue. In the attached XLSXform, I set a couple of null notes that stores the URL to the HFL and the where clause. Those are then called in the calculation. Though they could all go in the calculation, calling them as variables makes it more readable.
  • An important thing to note about the where clause is that if your inventory number is an integer, the where clause should be looking for an integer value, but if the inventory number is a string, the where clause should be looking for a string. E.g., INVENTORY_NUMBER = {Inventory} vs. INVENTORY_NUMBER = '{Inventory}'
  • In my testing, it seemed to work regardless but it could potentially cause issues.

The calculation that did work is the following:

pulldata("@layer", "getValue", "attributes.DESCRIPTION", ${hfl_url}, ${where_clause})

Documentation:

Query a Feature Layer 

Hope that helps!

20230912_Esri_Community_Support_Pulldata.gif

View solution in original post

10 Replies
Vinzafy
Frequent Contributor

Hey there,

I got this to work! A few notes:

  • getRecordAt/getValueAt are spatial queries. Since you're essentially doing an aspatial table lookup, you should be using getRecord/getValue.
  • getRecord would return the entire JSON which you can then pull from. For example, if there were numerous fields that you want to get data from, you can use getRecord to pull the entire JSON, then use pulldata("@json"...) to pull from that as opposed to making numerous queries on the feature layer.
  • Since you only want to return one attribute, you can use getValue. In the attached XLSXform, I set a couple of null notes that stores the URL to the HFL and the where clause. Those are then called in the calculation. Though they could all go in the calculation, calling them as variables makes it more readable.
  • An important thing to note about the where clause is that if your inventory number is an integer, the where clause should be looking for an integer value, but if the inventory number is a string, the where clause should be looking for a string. E.g., INVENTORY_NUMBER = {Inventory} vs. INVENTORY_NUMBER = '{Inventory}'
  • In my testing, it seemed to work regardless but it could potentially cause issues.

The calculation that did work is the following:

pulldata("@layer", "getValue", "attributes.DESCRIPTION", ${hfl_url}, ${where_clause})

Documentation:

Query a Feature Layer 

Hope that helps!

20230912_Esri_Community_Support_Pulldata.gif

ModernElectric
Frequent Contributor

@Vinzafy 

Question for you. I have been reworking my code in my spreadsheets for Survey123 Connect. Previously, the pulldata function was looking at a stand-alone table. Now, I am trying to pull the data from a hosted feature layer that is published from ArcGIS Pro. Some of the feature classes/fields use Domains. When I run the code for the autopopulate based on a previous entry, the field is populated with the Domain Code. That is not helpful. I need the field to populate the Domain Description. How do I ensure that happens?

Appreciate it

0 Kudos
Vinzafy
Frequent Contributor

Hey again,

I was stumped at first but I figured out a way! For some background, pulling the label of domains is possible via the jr:choice-name() function Great blog post from Ismael here. The syntax is the following:

 

 

jr:choice-name(choice, 'question')

 

 

Here, "choice" refers to the chosen code from the attribute domain; "question" refers to the actual question within the survey where the selection is made (e.g., select_one question).

The roadblock here is that the question containing the domain must be in the survey for jr:choice-name to work. Since the goal is to get the label of the domain from a separate hosted feature layer via pulldata(), that means there is no select_one question in the survey.

Let's consider the following domain for a field called "Animal" from the feature layer we want to pulldata() from:

CodeDescription
1Dog
2Cat

 

If we used pulldata(), what  is returned in the raw JSON is the code, not the description. For example:

 

 

{"attributes":{..."Animal":1,...}}

 

 

This doesn't work because we want, "Dog" not 1. We can't use jr:choice-name to retrieve "Dog" because, that domain isn't present in our survey.

However, what we can do is simulate that question in our survey. The way I did this was the following:

  • Create a select_one question in your survey (e.g., a question called "Animal_Domain_Placeholder") that contains the same codes and descriptions as the target domain (the {1: "Dog"  2: "Cat"} domain in this example).

    This question can be hidden and null so it doesn't actually display in your survey or create a new field in your schema. We're essentially using this as a placeholder to for jr:choice-name() to reference from.

  • Next, for the question where you want to return the description, in the calculation cell, setup jr:choice-name() with the pulldata() function nested as the "choice" parameter and the placeholder question created above as the "question" parameter.

    E.g.,

 

 

jr:choice-name(pulldata("@json", ${json_question}, "attributes.Animal"), '${Animal_Domain_Placeholder}')​

 

 

If the value returned from the pulldata() call is '1' (referring to "Dog"), what the jr:choice-name() function is doing is basically the following:

Take the value returned from the "choice" parameter (1 in this example) and search the choices for the question stated in the "question" parameter (select_one question called "Animal_Domain_Placeholder" in this example). If found, return the label.

Since we have created the corresponding domain in our survey, it recognizes that, based on the "Animal_Domain_Placeholder" question, the value of 1 refers to the label "Dog".

It always gets a bit confusing when you nest things, but hopefully that makes sense!

0 Kudos
ModernElectric
Frequent Contributor

@Vinzafy 

I assisted me with this awhile back, but was never really able to figure out how to get it right. I've been asked to make major improvements to our initial elementary Survey123 forms and working on the design and coding in excel. Figuring this out is going to help me on a number of forms.

Thank you

0 Kudos
Vinzafy
Frequent Contributor

My pleasure! Glad I was able to offer some help. Best of luck in the next iteration of your forms 😊

0 Kudos
ModernElectric
Frequent Contributor

That looks like it did the trick. That is exactly what I was trying to accomplish. 

(2) follow-up questions: 

    1: Is there a way to hide the where clause in the survey so it doesn't confuse or crowd the form for the user (Attachment).

    2: In the past, when I could create and publish a survey from Survey123 Connnect and record data, other users complained they could not see recorded surveys from others. Is this a known issue or more of a lack of knowledge on my part?

Appreciate it. 

0 Kudos
Vinzafy
Frequent Contributor

Awesome! Glad that worked for you. To answer your follow-up questions:

  1. Absolutely! Any line items can be hidden in a survey by setting the appearance for the item (column F) to "hidden".
  2. If I'm understanding you right, you're mentioning that users are unable to see submissions from other users of the survey? If so, I would start by going to the Survey123 website (https://survey123.arcgis.com/), click on the survey in question, then click on the collaborate tab > share results. There, you can control who is able to see survey results on the Survey123 website.


    If you're talking more about other users needing to see previous submissions in S123 directly, I would look to the "Inbox" feature.
0 Kudos
ModernElectric
Frequent Contributor

Appreciate it.  I believe this will set the foundation for what I need to accomplish.

Vinzafy
Frequent Contributor

Awesome! Happy to help 😊

0 Kudos