<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding Relationship Class to Featue Service in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223189#M48395</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I would like to add a relationship class to one of my feature services.&lt;/P&gt;&lt;P&gt;There is already a GlobalID - ParentGLobalID relationship, and&amp;nbsp; want to have second one based on a String (Name - ParentName).&lt;/P&gt;&lt;P&gt;I tried using ArcGIS Pro to achieve this, however,I'm getting this very useless error message here:&lt;BR /&gt;&lt;A href="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" target="_blank"&gt;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&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is there a way to add this relationship via REST, or any other way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 07:09:54 GMT</pubDate>
    <dc:creator>MarcoPoetsch</dc:creator>
    <dc:date>2022-10-19T07:09:54Z</dc:date>
    <item>
      <title>Adding Relationship Class to Featue Service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223189#M48395</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I would like to add a relationship class to one of my feature services.&lt;/P&gt;&lt;P&gt;There is already a GlobalID - ParentGLobalID relationship, and&amp;nbsp; want to have second one based on a String (Name - ParentName).&lt;/P&gt;&lt;P&gt;I tried using ArcGIS Pro to achieve this, however,I'm getting this very useless error message here:&lt;BR /&gt;&lt;A href="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" target="_blank"&gt;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&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Is there a way to add this relationship via REST, or any other way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 07:09:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223189#M48395</guid>
      <dc:creator>MarcoPoetsch</dc:creator>
      <dc:date>2022-10-19T07:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Relationship Class to Featue Service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223207#M48396</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/143552"&gt;@MarcoPoetsch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be achieved using the ArcGIS Python API similar to below.&lt;/P&gt;&lt;P&gt;Process:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Connect to AGOL&lt;/LI&gt;&lt;LI&gt;Access Feature Service&lt;/LI&gt;&lt;LI&gt;Get Layer and Layer ID&lt;/LI&gt;&lt;LI&gt;Get Table and Table ID (you can also relate to another Layer instead)&lt;/LI&gt;&lt;LI&gt;Create dictionary for Layer and Table relationships. (the example below shows a one-to-one, you can alter for alternate cardinality)&lt;/LI&gt;&lt;LI&gt;Update the Layer and Table definitions with the relationship&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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]})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 07:55:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223207#M48396</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-10-19T07:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Relationship Class to Featue Service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223725#M48427</link>
      <description>&lt;P&gt;Sweet. Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;May I ask you how I would DELETE a relationship class? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 09:41:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223725#M48427</guid>
      <dc:creator>MarcoPoetsch</dc:creator>
      <dc:date>2022-10-20T09:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Relationship Class to Featue Service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223737#M48429</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/143552"&gt;@MarcoPoetsch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recommend asking this a separate question so it has its own answer and for others to find the answer to it the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 10:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223737#M48429</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-10-20T10:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Relationship Class to Featue Service</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223741#M48431</link>
      <description>&lt;P&gt;here we go &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/deleting-relationship-class-from-featue-service/m-p/1223738#M48430" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-questions/deleting-relationship-class-from-featue-service/m-p/1223738#M48430&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 10:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/adding-relationship-class-to-featue-service/m-p/1223741#M48431</guid>
      <dc:creator>MarcoPoetsch</dc:creator>
      <dc:date>2022-10-20T10:25:02Z</dc:date>
    </item>
  </channel>
</rss>

