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.
Solved! Go to Solution.
@KenBuja has the right approach for an Array, but do be aware that FeatureSet objects cannot be accessed that way.
For a FeatureSet, you'll want to use First, which returns the first Feature from the set.
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
}
The Filter function returns either a FeatureSet or Array. Assuming the filter returns just one item, you should use
return tank[0].fuelFilled
When I try this I still get "Runtime Error: Cannot call member property on object of this type."
@KenBuja has the right approach for an Array, but do be aware that FeatureSet objects cannot be accessed that way.
For a FeatureSet, you'll want to use First, which returns the first Feature from the set.
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
}
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.
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.
That did it, thank you very much!