Adding related table to ArcGIS Online feature layer

59262
73
Jump to solution
01-08-2019 10:26 AM
EricGardecki1
New Contributor III

I'm trying to figure out how to add a relationship class (related table one-to-many) to a feature layer within AGOL. I do not have ArcGIS Desktop or Server (do have QGIS but I don't think that will help here).

The only info I was able to find led me to believe that it may be possible by editing the service definition JSON but I can't find any reference as to how to edit it to make it work.

What are my options here?

Also, is viewing/editing/adding to related tables supported in AGOL web apps yet (not just Collector)?

Thanks!!

73 Replies
KhaledHassen
Esri Contributor

I see your table does not have an ObjectId. You will have a problem in your table without objectId. All UX needs the objectId. Pl. drop the table and be sure to add ObjectId field name with your table.

Thanks

Khaled

0 Kudos
EricGardecki1
New Contributor III

I had added it at one time but removed it the last try in case that was the issue.  

This time around I added FID again but still having the same problem.

Any other thoughts?

0 Kudos
EricGardecki1
New Contributor III

I am seeing this error in the browser console after clicking the edit icon for related records:

TypeError: Cannot read property 'toLowerCase' of undefined

0 Kudos
KhaledHassen
Esri Contributor

Still do not see the objectId in the table. Pl. be sure to add it to the table field list when adding the table.

Khaled

0 Kudos
EricGardecki1
New Contributor III

Ok after digging around for a while it seems that the FID field I added was incorrect in the type field.  It needed to be type OID.  However, I did what I did because I was following this, which had the FID as type integer.

Add to Definition (Feature Service)—ArcGIS REST API: Services Directory | ArcGIS for Developers 

I was able to add a related record via the web app now, however there are still several problems.  

  1. The related table is now listed twice in the popup....presumably due to the deleting of the table prior to deleting the relationship.  I do not know how to delete the duplicate.
  2. I still cannot view the related records at all.  Nothing is listed after entering one.
  3. In Collector, I still cannot add a related record, or view existing.  Possibly due to #1 above.
0 Kudos
EricGardecki1
New Contributor III

I was able to delete the duplicate relationship by deleteFromDefinition

I still can't see the related records and when I try to add a new one in Collector, the app crashes each time.

0 Kudos
KhaledHassen
Esri Contributor

I see no relationship on your table.

I see also you are adding relationship like and it has a typo:

{

"relationships" :

[

   {

      "id" : 1, "name" :

     "Maintenance",

     "relatedTableId" : 1,

     "cardinality" : "esriRelCardinalityOneToMany",

     "role" : "esriRelRoleOrigin",

    "keyField" : "GlobalID",

    "composite" : false }   //// you have an extra "," here. Pl. remove it.

]

}

Thanks

Khaled

0 Kudos
EricGardecki1
New Contributor III

I can see the relationship in the JSON and in REST.  It is definitely there...

If I had an extra comma, the API errors out so that isn't possible.  Where did you find that?

0 Kudos
KhaledHassen
Esri Contributor

I see the relationship now. I saw the typo in the error log we have. 

I do see the field of type ObjectId but not seeing however the objectIdField property. 

"objectIdField" : "FID"

Pl. try to recreate the table and be sure to set this property to FID.

Thanks

Khaled
EricGardecki1
New Contributor III

That did it!  Thanks much!

Is there anything else I am missing in here to ensure I don't see any further issues?  This is the JSON for adding a new table to the layer service

{
"layers" : [
{
"name" : "Maintenance",
"type" : "Table",
"objectIdField" : "FID",
"fields" : [
{
"name" : "reference",
"type" : "esriFieldTypeGUID",
"alias" : "reference",
"sqlType" : "sqlTypeOther",
"nullable" : false,
"editable" : true,
"length" : 38,
"visible" : true,
"domain" : null,
"defaultValue" : null
},
{
"name" : "MaintDate",
"type" : "esriFieldTypeDate",
"alias" : "Maintenance Date",
"sqlType" : "sqlTypeOther",
"length" : 8,
"nullable" : true,
"editable" : true,
"domain" : null,
"defaultValue" : null
},
{
"name" : "MaintType",
"type" : "esriFieldTypeString",
"actualType" : "nvarchar",
"alias" : "Maintenance Type",
"sqlType" : "sqlTypeNVarchar",
"length" : 256,
"nullable" : true,
"editable" : true,
"visible" : true,
"domain" : null,
"defaultValue" : null
},
{
"name" : "Notes",
"type" : "esriFieldTypeString",
"actualType" : "nvarchar",
"alias" : "Notes",
"sqlType" : "sqlTypeNVarchar",
"length" : 256,
"nullable" : true,
"editable" : true,
"visible" : true,
"domain" : null,
"defaultValue" : null
},
{
"name" : "CreationDate",
"type" : "esriFieldTypeDate",
"alias" : "CreationDate",
"sqlType" : "sqlTypeOther",
"length" : 8,
"nullable" : true,
"editable" : false,
"domain" : null,
"defaultValue" : null
},
{
"name" : "Creator",
"type" : "esriFieldTypeString",
"alias" : "Creator",
"sqlType" : "sqlTypeOther",
"length" : 50,
"nullable" : true,
"editable" : false,
"domain" : null,
"defaultValue" : null
},
{
"name" : "EditDate",
"type" : "esriFieldTypeDate",
"alias" : "EditDate",
"sqlType" : "sqlTypeOther",
"length" : 8,
"nullable" : true,
"editable" : false,
"domain" : null,
"defaultValue" : null
},
{
"name" : "Editor",
"type" : "esriFieldTypeString",
"alias" : "Editor",
"sqlType" : "sqlTypeOther",
"length" : 50,
"nullable" : true,
"editable" : false,
"domain" : null,
"defaultValue" : null
},
{
"name" : "FID",
"type" : "esriFieldTypeOID",
"actualType" : "int",
"alias" : "FID",
"sqlType" : "sqlTypeInteger",
"length" : 4,
"nullable" : false,
"editable" : false,
"domain" : null,
"defaultValue" : null
}
]
}
]
}

0 Kudos