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!!
Solved! Go to Solution.
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
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?
I am seeing this error in the browser console after clicking the edit icon for related records:
TypeError: Cannot read property 'toLowerCase' of undefined
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
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.
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.
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
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?
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
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
}
]
}
]
}