Select to view content in your preferred language

Arcade Data Expression- Related Table

9160
14
Jump to solution
12-21-2021 05:55 AM
TSmith
by
Regular Contributor

Hello,

 

I am relatively new to arcade, and attempting to figure out how to use a data expression to feed indicators/gauges based on an inspection date field in a related table. 

I currently have a pop-up within the map that uses this expression:

 

 

 var BlowoffHistory= FeatureSetByRelationshipName($feature,"Blowoff_Flushing_Inspection")var LatestDate = Max(BlowoffHistory,"flushingdate") var FormatDate = Date(LatestDate) return FormatDate 

 

my goal is to reference related data and check to see if the most recent inspection date occurred within the last year. If it did not, the feature should be passed through to an indicator widget, displaying the assets that are overdue for inspection. Any pointers/tips on how to accomplish this? 

 

 

0 Kudos
14 Replies
TSmith
by
Regular Contributor

Realized there was a missing comma in the code, it works now. My only question now is how to highlight these features on the map? 

 

Thanks so much!

0 Kudos
jcarlson
MVP Esteemed Contributor

Glad to hear it! Adding the spatial component is not too difficult.

  1. In the FeatureSetByPortalItem function, set the final parameter to "true".
  2. In the section when we define the feat object, we need to include that geometry:
    var feat = {
    attributes: {
    assetid: f['assetid'],
    flushingdate: latest
    },
    geometry: Geometry(f)
    }
  3. When we establish the outdict object, put "geometryType: 'esriGeometryPoint'", or whatever geometry type we're dealing with here.

I always default to leaving geometry out of data expressions, as it can make the expression more resource-intensive to evaluate. But once you make those changes, you should be able to use the appropriate Action to zoom to / filter data in the map.

- Josh Carlson
Kendall County GIS
TSmith
by
Regular Contributor

You have been a tremendous amount of help. Is there any way I could grab data from fields in the related table? 

 

When I try this: 

 

f (latest < year_ago) {
        var feat = {
            attributes: {
                'valveID': f['assetid'],
                'vcycle' : f['vcycle'],
                'last_inspection': latest,
                'fintorque': rel_fs['fintorque'],
                'turns': rel_fs['turns']

 

it doesn't like trying to add those fields. Even when I set a variable 

 

var turns = rel_fs['turns'];
    var fintorque = rel_fs['fintorque'];

do I have to call a function like var turns  = Text(rel_fs['turns']); or something like that? 

0 Kudos
KimberlyK
Occasional Contributor

Hi Josh @jcarlson - I use quite a few of your examples that you post in the Community to help us out with data expressions. Thank you so much for generously addressing questions and offering your expertise.

I am currently working on a dashboard that includes the need to use related tables. I'm particularly stumped by the syntax needed in a data expression to use grouped values from a related table that are related to the feature layer by a projectID, and still be able to zoom to the location on the map that corresponds to those projectIDs in the feature layer. The related table is many:1 so the attributes in the table have to be grouped to be useable in a category selector widget or a table widget. When I read your reply, I thought maybe the bit of alteration you mention might be the key: "If you wanted to add a spatial component to this list, say, have the list items zoom to a location on a map, the expression would need to be altered, but not much." 

I updated my expression to include the spatial component, but I am still unable to use the select or zoom action on the feature layer in the map. If you have any additional suggestions, I would appreciate your help. Thanks.

0 Kudos
jcarlson
MVP Esteemed Contributor

It would probably be best to post this as its own question, and include the expression you've got so far.

- Josh Carlson
Kendall County GIS