How To: Modify Relationships of Hosted Services

3627
7
06-30-2015 05:52 PM
DavinShokes1
Occasional Contributor

Through the admin REST API, I've had some success creating 1:M relationships for existing hosted feature services. Why not just overwrite the service you ask? There is a bug during sd file creation in ArcMap, making republishing not an option.

I start out by updating the layer definition for the layer with the origin field via - https://services.arcgis.com/<Organization ID>/arcgis/admin/services/<ServiceName>.FeatureServer/<lay... In this case, the layer id is 0 and the origin field will be GlobalID. Here is what I add to the definition:

{

  "relationships" : [

    {

      "id" : 0,

      "name" : "Layer1sInLayer0",

      "relatedTableId" : 1,

      "cardinality" : "esriRelCardinalityOneToMany",

      "role" : "esriRelRoleOrigin",

      "keyField" : "GlobalID",

      "composite" : false

    }

  ]

}

The second layer has an id of 1 and the destination is a GUID field named "RelatedGUID"

This is what I add to the layer definition:

{

  "relationships" : [

    {

      "id" : 0,

      "name" : "Layer1sInLayer0",

      "relatedTableId" : 0,

      "cardinality" : "esriRelCardinalityOneToMany",

      "role" : "esriRelRoleDestination",

      "keyField" : "RelatedGUID",

      "composite" : false

    }

  ]

}

After running these two, the relationship appears valid in the ArcGIS online map viewer and Collector for ArcGIS.

Some things I've noticed:

  • Must be done on both layers separately. I Could not add both layer parts to the definition of the entire feature service.
  • Sometimes deleting relationships works. Other times I am unable to delete from the definition with a message saying a specific contraint doesn't exist. I do not see any sql server constraints visible from the REST service directory.
  • It doesn't seem as though relationship names or id's need to match for both layers.
  • Duplicate id numbers can be added to a layer and WILL BREAK IT!
  • I've only tested GlobalID to GUID but assume Integer to Integer would work.
  • I have not tested setting composite to true
  • I have not tested many to many
  • I have not had luck manipulating relationships with updateDefinition

My question for anyone reading: Is there another way to add/modify/delete relationships to existing services? I highly doubt this is supported and there isn't any REST API documentation.

Hopefully AGOL admins find this helpful. Relationships can be so powerful in a mapping application. It's too bad that we have to go to such extremes to apply them to hosted services when you can simply right-click create relationship class on the data behind ArcGIS Server services. Maybe enough people will break their services and we'll get a tool to manipulate hosted relationships!

7 Replies
XanderBakker
Esri Esteemed Contributor
Why not just overwrite the service you ask? There is a bug during sd file creation in ArcMap, making republishing not an option.

Hi RTC GIS ,

Thanks for sharing the method to modify the relationship of a hosted feature service. I do have some questions:

What version of ArcGIS (ArcMap and/or Pro) are you using? What kind of error do you encounter? Was this bug reported?

0 Kudos
DavinShokes1
Occasional Contributor

Xander Bakker, the publishing issue is improper template order. Since ArcMap 10.1 up to 10.3.1 feature templates seem to reorganize, with no discernible pattern, while staging the service definition file. It occurs when I use picture marker symbols matched to style on a string field with a unique values domain. Other users have posted about this same issue. Tickets and bugs closed in the past were marked low priority/no work around.

Since support has trouble reproducing the issue, I've made my own workarounds to script bulk symbology and template changes directly on the services. Downside: It's a grey area for getting support and I tend to stumble upon other bugs/unintended usages of the REST API. Upside: My scheduled sync scripts aren't phased and I don't have to download data with 100's of attachments after everyone goes home just to send it right back up.

0 Kudos
XanderBakker
Esri Esteemed Contributor

I'm going to dive into a sd file to see what can be done after it's creation. As far as I know it is a renamed zip. Is it possible to post a sample sd file that has the problems?

0 Kudos
DavinShokes1
Occasional Contributor

You are correct. sd files are compressed packages. I can provide some images of components in the sd file.

This is top level. I found the feature templates definition in the featureserver.json within .../servicedescriptions/featureserver/.

I just ran another test.

Here is an image of feature templates in the mxd. a subset of all available symbols and domain values starting with letter "A" or "B":

mxdtemplates.JPG

After staging the sd file I checked the featureserver.json types and see every domain values listed in a random order. Here is the map view edit panel after publishing

I could script sorting of the types in the json file in the sd file and overwrite the service, but REST updateDefinition is easier.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Okay, I see you explored your options and if the current method you are using is the easiest, then I suppose I can't be of any help to you. To bad this hasn't been corrected. We had registered a bug a few weeks ago and after quite a lot of effort they were able to reproduce it and this week we received the hot fix. Are you sure Esri support can't help on this and the bug is impossible to reproduce?

0 Kudos
CadeFurnas3
New Contributor

Thanks for this information. Wow, this is a frustrating bug. Do you happen to have the bug report and hotfix numbers? Thanks,

0 Kudos
DavinShokes1
Occasional Contributor

NIM100346 wont be addressed

NIM099522 open

ENH-000085269 open

0 Kudos