arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

Example of how to create joined view use the API for Python

Open astjohn-RM opened this issue 7 months ago • 3 comments
trafficstars

Is your feature request related to a problem? Please describe. I am trying to automate creation of hosted joined views, as we use many of them that must be maintained to standards across AGO organizations. I am led to believe that this is the intended output of this method, but can not figure it out: https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.ViewManager.create_join_layer

For example, some of my latest attempt:

from arcgis.gis._impl._dataclasses._viewdc import JoinType
from arcgis.features import FeatureLayer, FeatureLayerCollection, Table

flc_item = gis.content.search(rf"id:<hfl_itemid>", item_type="Feature Service")[0]

for lyr in flc_item.layers:
    if (len(lyr.properties['relationships']) > 0):
       # Initialize feature layer collection from URL of specific layer
        flc = FeatureLayerCollection(flc_item.url + r"/" + str(lyr.properties.id))
        for rel in lyr.properties['relationships']:
            if ("WorkOrders" in rel['name']):
               # Initial table from URL of related table to feature layer (in same hosted feature service)
                tbl = Table(flc_item.url + r"/" + str(rel['relatedTableId']))
                view_item = flc.view_manager.create_join_layer(
                                join_name=rf"{rel['name']} test joined view", 
                                target_join_fields=["FeatureGUID"],
                                join=tbl,
                                join_fields=["GlobalID"],
                                join_type=JoinType.INNER,
                                include_geometry=True,
                                owner=gis.users.me
                            )
                print(rf"Created joined view for relationship: {rel['name']}")

Describe the solution you'd like I would love to see a working example to create a hosted joined view between a feature layer and its related table, so I can better understand how the manager classes are used. I've run into various errors as I am trying many things here, and am not sure whether I am running into bugs or misunderstandings.

Additional context Also note that I must use private classes to access the JoinType enumeration.

astjohn-RM avatar Apr 21 '25 22:04 astjohn-RM