Hello! I’m working with a 1:M relationship between two feature classes in an ArcGIS Enterprise 11.3 environment. Layers are published through ArcGIS Server, brought into ArcGIS Portal, and consumed using Map Viewer and Field Maps.
The relationship is based on GlobalID (parent) → ParentGUID (child).
The parent layer includes a field called “Inactive”, which indicates whether a site is active:
In my web map, I’ve applied a filter to the parent layer to only show active sites (Inactive = '0'), and that works perfectly.
I’d like to apply the same logic to the related WNV_SiteVisits table, so it only shows point site visits related to the active parent site. However, since the “Inactive” field exists only in the parent layer, and Arcade can’t be used to reference related records in layer filters or symbology, I’m running into a roadblock.
I was hoping I could use an Arcade expression in the layer’s filter view, but it seems filters in Map Viewer only allow basic expressions using dropdown options. I would think in most 1:M relationships—especially with spatial child features, you’d want child records filtered out if their parent was filtered/excluded from the map view.
So far, I’ve explored almost every setting in Map Viewer, but I can’t find a way to do this. Of course, I could be missing something obvious lol!
Has anyone figured out a way to do this kind of filtering in map viewer?
Hi @JamesBooth,
In the past, I have used the ArcGIS API for Python and scheduled to run a Notebook at a defined interval. The workflow was...
I'd also be interested to hear about other options.
All the best,
Glen
Hello again @Clubdebambos, I was wondering if you were willing to share an example of the Python script you utilized to filter related records? And I'm assuming this would work on WebMap Layers in Enterprise Portal? My data needs to reference its Enterprise SDE source. Not sure if that's relevant here or not, still piecing together some web mapping concepts! 🙂 Appreciate any help!
Hi @JamesBooth,
I haven't had the opportunity to test the below with the ArcGIS API for Python version 2.4.0+, but the workflow stated above would equate to the below. Code is commented. Save a copy of your WebMap and test it out. This will only work if your layers are not in a Group Layer. You would need to refactor the code to account for that. If you have ArcGIS Pro 3.4.0 or above, you will have access to the API version 2.4.0.
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.map import Map
################################################################################
## FUNCTIONS ###################################################################
## function to return index of WebMap layer
def getLayerIndexByName(wm_item, lyr_name):
try:
lyr_index = [index for index, lyr in enumerate(wm_item.get_data()["operationalLayers"]) if lyr["title"]==lyr_name][0]
return lyr_index
except IndexError:
return None
################################################################################
## USER INPUT ##################################################################
## WebMap Content Item ID
wm_item_id = "WM_ITEM_ID"
## parent layer name (as per the WebMap)
parent_name = "WNV_StagnantWaterSites"
## related layer name (as per the WebMap)
related_name = "WNV_SiteVisits"
################################################################################
## ACCESS PORTAL ###############################################################
## access Portal
portal = GIS("home")
# or
# portal = GIS(url, username, password)
################################################################################
## GET ITEM OBJECT & MAP OBJECT ################################################
## get the WebMap as an Item object
wm_item = portal.content.get(wm_item_id)
## get the WebMap as a Map object
webmap = Map(wm_item)
## get the WebMap JSON Definition (as a dictionary)
wm_item_data = wm_item.get_data()
################################################################################
## GET PARENT GLOBALIDS ########################################################
## get the index of the parent layer in the WebMap
parent_lyr_index = getLayerIndexByName(
wm_item=wm_item,
lyr_name=parent_name
)
## get the URL to the Parent Feature Layers
parent_lyr_url = wm_item_data["operationalLayers"][parent_lyr_index]["url"]
## get the Parent Feature Layer as a FeatureLayer object
parent_fl = FeatureLayer(parent_lyr_url)
## query the FeatureLayer returns a list of the GlobalIDs
parent_guids = parent_fl.query(where="Inactive = '0'", out_fields=["GlobalID"], return_geometry=False).sdf["GlobalID"].tolist()
################################################################################
## FILETER THE RELATED LAYER ###################################################
## prepare the SQL Expression for the related layer filter
filter_exp = "ParentGUID IN ('{0}')".format("','".join(parent_guids))
## get the index of the parent layer in the WebMap
related_lyr_index = getLayerIndexByName(
wm_item=wm_item,
lyr_name=related_name
)
## set the property of the layer to update
options_dict = {
"layerDefinition" : {
"definitionExpression" : filter_exp
}
}
## apply the update to the layer
webmap.content.update_layer(
index=related_lyr_index,
options=options_dict
)
## upate the WebMap
webmap.update()
################################################################################
Let us know how you get on.
All the best,
Glen
Thanks @Clubdebambos!
I will see if I can replicate your strategy and I'll report back!
But yes, if anyone else has other approaches, would love to hear them!
I've looked at this thread: Hosted Feature Layer View - filter related table r... - Esri Community, but I'd really like to avoid creating another field on my child layer.