Arcade expression, Runtime error

2289
6
Jump to solution
12-16-2021 11:42 AM
Labels (1)
Claudio_Verina
New Contributor II

I am attempting to create a pop-up in a web map that shows information from a table of Survey123 results.

We have a map of fuel tanks, which serves as the main layer I want users to be able to click on and see the pop-up. Our field staff fill out Survey123 forms with a repeat for each tank, recording how much fuel was filled. The feature class and the table are related by a tankID field, in a one-to-many relationship. Not every tank has received a fill yet, so not every record in the layer has a match in the table.

Below is the expression I am trying to make work. This puts out an error, "Execution Error:Runtime Error: Cannot call member property on object of this type. fuelFilled"

 

var layerID = $feature.tankID

var formID = FeatureSetByName($map,"TankFillRecord")

var filterStatement = "tankID = @layerID"

var tank = filter(formID, filterStatement)

return tank.fuelFilled

 

 

Ideally, when this is working the expression will return the value of the fuelFilled field in the pop-up.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

@KenBuja  has the right approach for an Array, but do be aware that FeatureSet objects cannot be accessed that way.

jcarlson_0-1639684819881.png

For a FeatureSet, you'll want to use First, which returns the first Feature from the set.

jcarlson_1-1639684888811.png

You'll want to consider, though, whether or not multiple values may be returned by your filter, and how to handle cases where there are no records in the related table. Try something like this:

 

var layerID = $feature.tankID

var formID = FeatureSetByName($map, "TankFillRecord")

var filterStatement = "tankID = @layerID"

// Filter for matching tank ID
var tanks = Filter(formID, filterStatement)

// Check if records exist, return default response if not
if (Count(tanks) == 0){
    return "No fill records yet."
} else {
    // Order records by objectid; you can set this to some date field, too
    var ordered_tanks = OrderBy(tanks, "objectid DESC")
    var tank = First(ordered_tanks)
    return tank.fuelFilled
}

 

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

The Filter function returns either a FeatureSet or Array. Assuming the filter returns just one item, you should use

 

return tank[0].fuelFilled

 

 

0 Kudos
Claudio_Verina
New Contributor II

When I try this I still get "Runtime Error: Cannot call member property on object of this type."

0 Kudos
jcarlson
MVP Esteemed Contributor

@KenBuja  has the right approach for an Array, but do be aware that FeatureSet objects cannot be accessed that way.

jcarlson_0-1639684819881.png

For a FeatureSet, you'll want to use First, which returns the first Feature from the set.

jcarlson_1-1639684888811.png

You'll want to consider, though, whether or not multiple values may be returned by your filter, and how to handle cases where there are no records in the related table. Try something like this:

 

var layerID = $feature.tankID

var formID = FeatureSetByName($map, "TankFillRecord")

var filterStatement = "tankID = @layerID"

// Filter for matching tank ID
var tanks = Filter(formID, filterStatement)

// Check if records exist, return default response if not
if (Count(tanks) == 0){
    return "No fill records yet."
} else {
    // Order records by objectid; you can set this to some date field, too
    var ordered_tanks = OrderBy(tanks, "objectid DESC")
    var tank = First(ordered_tanks)
    return tank.fuelFilled
}

 

- Josh Carlson
Kendall County GIS
Claudio_Verina
New Contributor II

Thank you, this works and returns the expected value! However, I need to retrieve the last fill on each tank, and First() returns the earliest date when using OrderBy().

I tried using First(Reverse(ordered_tanks)) but that gave me an Invalid Parameter error.

0 Kudos
jcarlson
MVP Esteemed Contributor

So, that's where we'll need to look at other ways of ordering your records. If you have a date field, try something like:

var ordered_tanks = OrderBy(tanks, "some-date-field DESC")

That should get the most recent records to the top, and First will grab the latest one.

- Josh Carlson
Kendall County GIS
Claudio_Verina
New Contributor II

That did it, thank you very much!