Arcade error when accessing empty feature set

5144
15
Jump to solution
04-26-2020 08:51 AM
DonMorrison1
Occasional Contributor III

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:

  • Count(fs)
  • for (var f in fs) {}
  • First(fs)

What is the trick to allow me to detect in my code that the feature set is empty?  

15 Replies
KARIMLABIDI
Occasional Contributor

Hello Everybody,

I have the same problem than DonMorrison1 but I can't solved it. I got the same error msg.

KARIMLABIDI_1-1647618557004.png

KARIMLABIDI_2-1647618594559.png

I tried the little code of Dan but it doesn't work .

Any idea?

Thanks a lot

 

 

 

0 Kudos
JohannesLindner
MVP Regular Contributor

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, ", ")

Have a great day!
Johannes
0 Kudos
KARIMLABIDI
Occasional Contributor

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.

KARIMLABIDI_0-1647850546749.png

KARIMLABIDI_1-1647850712363.png

 

 

0 Kudos
JohannesLindner
MVP Regular Contributor

Hmmm. Try adding this at the start of your script:

if(IsEmpty($feature.IDARRET)) {
  return "null"
}

 


Have a great day!
Johannes
0 Kudos
KARIMLABIDI
Occasional Contributor

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

Tags (1)
0 Kudos
JohannesLindner
MVP Regular Contributor

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.


Have a great day!
Johannes
Tags (1)
0 Kudos