Hi there,
I would like to add a relationship class to one of my feature services.
There is already a GlobalID - ParentGLobalID relationship, and want to have second one based on a String (Name - ParentName).
I tried using ArcGIS Pro to achieve this, however,I'm getting this very useless error message here:https://pro.arcgis.com/en/pro-app/2.9/tool-reference/tool-errors-and-warnings/160001-170000/tool-errors-and-warnings-160251-160275-160270.htm
Is there a way to add this relationship via REST, or any other way?
Hi @MarcoPoetsch
This can be achieved using the ArcGIS Python API similar to below.
Process:
from arcgis import GIS ## connect to AGOL agol = GIS("home") ## get the feature service using the item id item = agol.content.get("FS_ITEM_ID") ## get the Feature Layer and its ID ## you might need to replace 0 with the proper layer index if more than one layer lyr = item .layers[0] lyr_id = lyr.properties.id ## get the Table and its ID ## you might need to replace 0 with the proper table index if more than one table tbl = item.tables[0] tbl_id = tbl.properties.id ## a dictionary containing the relationship properties for the Feature Layer ## REPLACE LAYER_FIELD with the name of your matching field in the layer lyr_rel_dict = { "name": "Layer_to_Table", "relatedTableId": int(tbl_id), "cardinality": "esriRelCardinalityOneToOne", "role": "esriRelRoleOrigin", "keyField": "LYR_FIELD", "composite": True } ## a dictionary containing the relationship properties for the Table ## REPLACE TABLE_FIELD with the name of you matching field in the table tbl_rel_dict = { "name": "Table_to_Layer", "relatedTableId": int(lyr_id), "cardinality": "esriRelCardinalityOneToOne", "role": "esriRelRoleDestination", "keyField": "TABLE_FIELD", "composite": True } ## update the relationship properties in the Feature Layer and Table lyr.manager.add_to_definition({"relationships" : [lyr_rel_dict]}) tbl.manager.add_to_definition({"relationships" : [tbl_rel_dict]})
Sweet. Thanks @Clubdebambos May I ask you how I would DELETE a relationship class? 🙂
I recommend asking this a separate question so it has its own answer and for others to find the answer to it the future.
here we go @Clubdebambos https://community.esri.com/t5/arcgis-online-questions/deleting-relationship-class-from-featue-service/m-p/1223738#M48430
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.