Select to view content in your preferred language

Dashboard Details - Data Expression to Filter for Attachments

199
4
4 weeks ago
Labels (1)
Teresa_Blader
Occasional Contributor III

Hi! I am trying to create a Dashboard data expression that will let me filter out features without attachments on a feature layer. I'm a noob when it comes to loops and dictionaries. Any suggestions??  I was thinking I'd just add a field to the feature set and store the counts and filter off of that. I've got as far as below, but just doesn't seem to work. I think I'm mixing feature sets with arrays and not pushing correctly.

Otherwise Details shows all the features whether they have attachments or not which is awkward. This would be for an ongoing editing project so doing a one time calculation won't be the trick.

 

Thanks!!

Teresa_Blader_0-1715821384764.png

 

 

var responses = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),'e5f9d47a5ee84f0e97a377912cdae9f6',0,['*'],false)

var responses = {
  'fields': [{
    'attributes': {
      'name': 'counts', 
      'alias': 'Attachment Count', 
      'type': 'esriFieldTypeInteger'
    }
  }]
}

for (var nf in responses){
  var counts = Count(Attachments(nf))}
  responses.counts = {
    'attributes':{
      'counts': nf.counts
    }
}
return responses

 

 

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
4 Replies
DarraghOSullivan
Occasional Contributor

I'm trying to do the same thing - to filter features with more than 1 attachment - either in a dashboard or a webmap. I've been trying to use Count(Attachments($feature)) but the only place I can successfully get it to work at all is within a popup but that is no use when it comes to filtering. Even if I could get the expression in a label it would be useful but it's not working... Any ideas?

0 Kudos
Teresa_Blader
Occasional Contributor III

I did get a count to return at least when I wrapped the FeatureSetByPortalItem with the First() function - but that would be on a single feature - a good start though. For dashboard data expression, we want a feature set obviously... so a loop has to be involved and it has to push the features with the attachments. So I think it's possible I just have no experience with loops and how to use the loop to filter a feature set. Hoping someone jumps in and helps! 

var responses = First(FeatureSetByPortalItem(Portal('https://www.arcgis.com'),'e5f9d47a5ee84f0e97a377912cdae9f6',0,['*'],false)))

var counts = Count(Attachments(responses))

return counts

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
DarraghOSullivan
Occasional Contributor

Hi Teresa, I'm new to FeatureSets as well. Maybe in the meantime we can keep trying between us! I notice from the documentation here: 

https://developers.arcgis.com/arcade/guide/featuresets/#:~:text=You%20can%20also%20create%20a,source....

and here:

https://doc.arcgis.com/en/dashboards/latest/reference/authoring-data-expressions.htm

That they usually return a FeatureSet()  ... might return FeatureSet(responses) work in your case?

0 Kudos
Teresa_Blader
Occasional Contributor III

Sadly wrapping it in FeatureSet doesn't work because I don't have the loop set up correctly.

Teresa Blader
Olmsted County GIS Specialist
0 Kudos