Arcade Popup Related Table - Map Service

1139
6
Jump to solution
08-04-2021 11:17 AM
MSDC
by
New Contributor II

I'm just starting to play around with Arcade and am trying to do something for which I've found plenty of documentation...  configure a point layer's pop-up to display data from a related table.  I'm having little luck and wanted to confirm whether it's because my data is served as a map service through REST endpoint.  There's actually a relationship class built into it but it doesn't seem to matter. 

I have a map in our enterprise Portal that has various feature layers and a related table that shares an ID field.  I'm trying to configure the popup of one of my point layers to pull data from a few fields of the related table but can't get it to click.   Configuring the popup for the related table shows all the various globals like $map, $datastore, etc but the point layer (where I assume I'd want to put the arcade expression) only has $feature globals tied to the field names.   

So, my basic question is...can you do this with features/layers from a map service?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Frequent Contributor

Hm. That's very odd. Could it be because the layer is added as the full MapServer service? Try adding each layer individually using their respective layer indices, i.e., .../MapServer/0, etc. The web map will treat the added layer more like a Feature Layer than a Map Image.

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
jcarlson
MVP Frequent Contributor

This sort of thing depends a lot on how the layers in question are stored or structured, but it should still be possible, even if all you have is a shared field. It will also look differently depending on whether your related table holds multiple related records or just one corresponding row. Here's how you might get a single related attribute based on a matching attribute.

var x = $feature['some-id']

var fs = FeatureSetByName($map, 'Layer Name', ['fields', 'you', 'need'], false)

var filt = Filter(fs, 'corresponding_id_field = @x')

var first_feat = First(filt)

return first_feat['one of the fields']

 More information regarding your layers and the desired output would help.

- Josh Carlson
Kendall County GIS
0 Kudos
MSDC
by
New Contributor II

Well, that's encouraging.  The thing is, I can't seem to access globals like $map from any of the layers (see screenshot).

I can't share the map service or the portal map as both are internal to my org.  But basically everything is coming from an enterprise gdb.  The service has a dozen or more feature layers but for this example, I'll just name one or two.  I'm trying to accomplish the same thing for each feature layer:  build a pop-up that includes some data from fields from a related table.  There's relationship classes built between each of them and the related table (I'll call it "Link Table" here).   Feature layers and related table share a common field "BLDG_ID".

Let's say, click on a point from "Building Points" layer, and it'll show data from fields in Link Table such as "Field1_ID", "Field2_ID".  Relating from the layer to the link table should generally return only one result.

I've a web map in portal that pulls all layers from the map service.   I'll be generic and give an idea of how the service is structured:

Map Service:

https ://mymapservices.com/arcgis/rest/services/BldgData/MapServer       

Map Name: Building Data

Layers:

  • Building Point (0)
  • Building Poly (1)

Tables:

  • Link Table (20)

-----

Layer: Building Point (ID: 0)
Name: Building Point

Fields:

  • OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
  • RESNAME ( type: esriFieldTypeString , alias: Resource Name , length: 250 )
  • BLDG_ID ( type: esriFieldTypeString , alias: BLDG_ID , length: 5 )

Relationships:

  • MyBldgDB.DBO.Link_Table (0) -- Related To:  LINK TABLE (20)

------

Layer: LINK TABLE (ID: 20)
Name: LINK TABLE
  • OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
  • BLDG_ID ( type: esriFieldTypeString , alias: BLDG_ID , length: 5 )
  • FIELD1_ID ( type: esriFieldTypeString , alias: FIELD1_ID , length: 5 )
  • FIELD2_ID ( type: esriFieldTypeString , alias: FIELD2_ID , length: 5 )

Relationships:

  • MyBldgDB.DBO.BLDG_PT (0) -- Related To: Building Point (0)
  • MyBldgDB.DBO.BLDG_PY_ (1) -- Related To: Building Poly (1)

----

Portal web map has all layers pulled from this service under BldgData in ToC.

Not sure if this is helpful so I can try to simplify if need be.

0 Kudos
jcarlson
MVP Frequent Contributor

Are you, by chance, editing the expression from the map window inside of Web App Builder? I see that error message when attempting inter-layer expressions from there.

- Josh Carlson
Kendall County GIS
0 Kudos
MSDC
by
New Contributor II

Not even in web app builder.   Simply inside a web map in which I've added the layers and tables from the map service.  Much like this https://www.dvginteractive.com/arcgis-arcade-to-power-up-your-pop-ups-part-1/

In my map, choosing configure pop-up window from the layer, add attribute expression.  Going here for the related table, I can easily see all the globals and layers like $map, $datastore, etc.  But not so if I go to the point layer which is where, I believe, I should be configuring the popup

0 Kudos
jcarlson
MVP Frequent Contributor

Hm. That's very odd. Could it be because the layer is added as the full MapServer service? Try adding each layer individually using their respective layer indices, i.e., .../MapServer/0, etc. The web map will treat the added layer more like a Feature Layer than a Map Image.

- Josh Carlson
Kendall County GIS
MSDC
by
New Contributor II

Ahah!   Great solution.  I still need to now sort out the actual code but I'm now seeing the globals come up as expected so perhaps between what you posted above and the blog example, I can sort it out.  I'll mark this as solved and reply back only if I get stuck further (I actually need to also figure out how to label features on the map from the related table as well).