Select to view content in your preferred language

Trouble creating a data expression for survey feature layer within ArcGIS Dashboard.

113
0
a month ago
Labels (1)
DanielRutigliano
New Contributor

 

I am trying to create a dashboard that will monitor travel locations using Survey123. The survey contains repeats just in case respondents travel to multiple countries. 

I am not well versed in Arcade, but I am trying to create a data expression that takes a layer/table with a GlobalID. Finds related records in a child table/layer with a field ParentGlobalID then matches that GlobalID. From there, its returns related data so you can use it in a Dashboard element (list, chart, etc.).

I keep running into an issue where it can't find the $datastore. I have the web map set up correctly, but it keeps giving me an error saying "Test execution error: Compilation error - Line : 1,7 Identifier not recognized. Verify test data."

Any help is appreciated!

// Get parent layer (Survey)
var parentLayer = FeatureSetByName($datastore, "Form_1", ["GlobalID"], false)

// Get repeat layer (child)
var repeatLayer = FeatureSetByName($datastore, "Travel Locations", ["ParentGlobalID", "Select the country You will be traveling to", "OBJECTID"], false)

// Empty array for results
var relatedRepeats = []

// Loop through parents
for (var parent in parentLayer) {
    var parentID = parent["GlobalID"]
    
    // Find repeat features where ParentGlobalID matches this parent
    var repeats = Filter(
        repeatLayer,
        "ParentGlobalID = @parentID"
    )
    
    // Add all matching repeats to results
    for (var r in repeats) {
        Push(relatedRepeats, r)
    }
}

// Return repeats as FeatureSet
return FeatureSet(Text(relatedRepeats))

 

0 Kudos
0 Replies