I'm just starting to use Arcade - like it a lot so far but there is one scenario that I can't figure out. I want to retrieve the set of related records associated with a feature for my ArcGIS Online web map popup. I can do this with this statement
var fs = FeatureSetByRelationshipName($feature, "Program", ["ProgramName"], false);
It works great except when the feature has no related records. I still get a FeatureSet returned, and I would expect it to contain zero features. But any method I use to access the FeatureSet returns "Execution Error:Cannot read property 'toString' of null". I've tried all of the following:
What is the trick to allow me to detect in my code that the feature set is empty?
Solved! Go to Solution.
Hello Everybody,
I have the same problem than DonMorrison1 but I can't solved it. I got the same error msg.
I tried the little code of Dan but it doesn't work .
Any idea?
Thanks a lot
Your "build out popup" code is wrong.
If you only want to return the first entry of relateData:
var firstRelateData = First(relateData)
if(firstRelateData == null) { // no related data
return "null"
}
return firstRelateData.num_arret
If you want to return all related features:
if(Count(relateData) == 0) { // no related data
return "null"
}
var all_num_arrets = []
for(var f in relateData) {
if(f.num_arret != null) {
Push(all_num_arrets, f.num_arret)
}
}
return Concatenate(all_num_arrets, ", ")
Thank you Johannes but I Got the same problem. I can't count the relateData with the filter, the problem is in.
I don't understand this error msg because I have data in each row of my table.
Hmmm. Try adding this at the start of your script:
if(IsEmpty($feature.IDARRET)) {
return "null"
}
yes it works. Thank you!!
Juste one more question about it: do U know how can i put a little symbol just before my attributes. When i do like this
for(var f in relateData) {
if(f.num_arret != null) {
Push(all_num_arrets,
` "https://xxxxxxxx/rest/content/items/9e3929af55db440ea45c5f72e37cd3c5/data" ${f.hor_theo_1mn} `)
Push(all_num_arrets,
` "https://xxxxxxxx/rest/content/items/9e3929af55db440ea45c5f72e37cd3c5/data"${f.hor_theo_2mns} `)
}
}
, it just gives me the URL and not the image.
Thank you
Arcade doesn't evaluate HTML. Maybe what you want to do is possible, but it will be a little complicated.
I suggest posting a new question for this, as this goes far beyond the scope of the original question, and you'll get more views and potential answers.
Hello, I'm getting an issue trying to run this procedure but I can't quite figure out what's wrong. Here's my code:
var assets = FeatureSetByRelationshipName($feature, 'epgdb.PARKS.Asset_Inventory', ['*'], true)
console(assets)
console(count(assets))
console(typeof(assets))
// Get the first park asset (should only be one)
var asset = First(assets)
Expects(assets, 'AssetType')
// If there was an asset, return the AssetType of it,
// Otherwise, return null
if (!IsEmpty(asset)) {
return asset['AssetType']
} else {
return null
}
I have park assets, with a related inspection table. The table is where I'm placing this code, and the relationship name in the featureSetByRelationshipName function is the backward path label from my EGDB relationship class (is that correct?)
I've tried adjusting a lot of the parameters but the closest I get is always returning null:
The console messages indicate 0 assets, which I guess makes sense considering this is just in the expression builder and probably doesn't know what the related table would be targetting?
The problem is that when I open Field Maps and try to create a related record, the field I add the calculation to just gives me the error: "Failed to calculate"