Select to view content in your preferred language

Creating a Relationship between 2 different hosted feature layers

06-27-2023 04:15 AM
Occasional Contributor

Hi All, I'm wondering if anyone is able to help please as i'm very new to Python. I have a hosted feature layer stored in AGOL, which includes 1 polygon layer and 4 tables (all related back to the polgon layer). 

I am wanting to add a new table into this hosted feature layer and then create a relationship between this new table and the polygon layer. I have come across this document which highlights the python script: How To: Add a Relationship Class to a Hosted Feature Layer Using ArcGIS API for Python (, but looking at it, i get the impression it's thinking the feature table is already within the hosted feature layer and it's only stating me to input the "Access the hosted feature layer and retrieve the item ID" once.... am I right?

Is what I am after acually doable? I don't know of an easy way to add the table into the existing hosted feature layer already and i'm not able to export and republish due to access is constantly required.

0 Kudos
2 Replies
Occasional Contributor III

I have recently embarked on exactly the same. It is possible, but as you allude to you need the new table to be also in the hosted feature layer. This can be achieved via the use of additional; JSON, wrapped in a python command as instructed in this blog article

So essentially a tow step process:

1. Add new table to existing hosted feature layer.
2. Create the relate.

A word of warning. Ensure that you set the relationship IDs top be unique. If you reuse one, it badly confuses the existing relationships in your layer

Occasional Contributor

Thank you Richard, I was struggling to find a post to help me with step 1. Appreciate your help!