Select to view content in your preferred language

Auto-populate survey with attributes from more than one layer

3645
6
03-09-2021 11:56 AM
JeffreyMotz
New Contributor

Is it possible to auto-populate a survey with attributes from more than one layer? I'm thinking of a web app where a user clicks on the map, attributes from multiple layers appear along with a link to a URL configured with parameters of the collected attributes.

0 Kudos
6 Replies
DougBrowning
MVP Esteemed Contributor

Yes a do this.  It works in AGOL and now the new Field Maps (not in Collector).

Take a look at FeatureSet functions in Arcade.  

Here is some sample code for you using 1 layer.  You can make several arcade expressions and pass all of them over.  (note current bug requires all fields to be returned.

var sql = "PointID = '" + $feature.PointID + "'";
var tbl = Filter(FeatureSetByName($map,"Points", ["*"], false), sql);
return First(tbl).DesignLat

DougBrowning_0-1615320799409.png

arcgis-survey123://?itemID=2fb3880b8631451cac08f1653f350787&field:PointID={PointID}&field:EvaluationID={expression/expr0}&field:FieldEvalDate={FieldEvalDate}&field:FieldEvalStatus={FieldEvalStatus}&field:DesignLat={expression/expr6}&field:DesignLong={expression/expr7}&field:AvgTypicalBankfullWidths={expression/expr1}&field:CollectCoreSubset1={expression/expr8}&field:CollectCoreSubset2={expression/expr9}&field:CollectCoreSubset3={expression/expr10}&field:Supplementals={expression/expr11}&field:CollectGreenlineVegComp={expression/expr12}

Hope that helps.

ScottLehto1
Occasional Contributor

Hi Doug,

          Thanks. The example helps for sure. I have two questions:

1) In your URL Link string above, i see you use both the {expression/expr#} syntax to pass a value and the {FieldName}. I'm just wondering what the difference is in terms of functionality. I'm sure there is good reason but I am new to this, so i am missing something.

2)  So when i click my my link in the popup, i am pushed to Survey123 where i edit the record, and then submit my record in S123. However, a new record is created in AGOL instead of an update/edit. In other words, when i click on the link, the URL is pushing the values I want to use to the Survey123 Form, but it looks like its creating a new record versus updating the old one.

I was wondering and hoping you might be able to shed some light on that.

 

Thanks Doug. You've helped me out a lot.

         

0 Kudos
DougBrowning
MVP Esteemed Contributor

&field:EvaluationID={expression/expr0} is to pass a value from Arcade

&field:PointID={PointID} is to pass a field from Collector or Field Maps.

Yes this was all designed to add not edit.  App does not support an edit only the web app.  Here is one post but there are more.

https://gis.stackexchange.com/questions/358709/edit-and-update-existing-features-in-a-collector-app-...

I personally always add records vs edit to track all visits.

Hope that helps.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Note it seems like the field list bug is now fixed.  That means you can do this and it will be much faster for large layers.

var tbl = Filter(FeatureSetByName($map,"Points", ["DesignLat"], false), sql);

0 Kudos
jcarlson
MVP Esteemed Contributor

I think the answer to this (and most questions) is "it depends".

Using built-in web maps / apps

In order to populate a Survey123 URL with attributes from a layer, you'd need to create an expression on one of your feature layers. That's pretty straightforward, and examples abound.

To get more than one layer, the limitation here is that the expression that generates a URL needs to come out of a single layer. The other layers would need to be brought into the same expression by means of Arcade's geometry functions, like Intersects, etc., in order to grab an attribute from another layer.

This might be okay, but then, I don't know the shapes of your layers. I can easily imagine a situation in which the clicked location does not correspond to the same feature that would be returned from the geometry functions.

Using Custom JS

If you built your web map from scratch, you could probably get a clicked coordinate to run a series of intersections with your layers and spit out a single URL. I don't know enough JS to be of much help there, but you might check out the Developers page and see if it's worth pursuing.

- Josh Carlson
Kendall County GIS
0 Kudos
RyanBohan
Frequent Contributor

Should be doable in arcade...something like

var URL = "https://survey123.arcgis.com/share/(your survey)?"

URL += "field:ID=" + $feature.OBJECTID
URL += "&field:business_address=" + "feature["business_owner_name"]"
URL += "&field:business_activity=" + "feature["business_activity"]"

return URL

0 Kudos