Adding related table to ArcGIS Online feature layer

59091
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
EricGardecki1
New Contributor III
0 Kudos
KhaledHassen
Esri Contributor

Eric,

I see the GUID field is defined as editable=false

 {       "name" : "reference",        "type" : "esriFieldTypeGUID",        "alias" : "reference",        "sqlType" : "sqlTypeOther",        "length" : 38,        "nullable" : false,        "editable" : false,        "domain" : null,        "defaultValue" : null     }, 

The guid field needs to be editable. The Globald is the only field that needs to have editable=false.

Sorry we do not have a way to change this property from the admin API. You can drop the relatiohship and the guid column and repeat the process . Will be good to start from scratch just to be sure all are good. 

Thanks

Khaled

EricGardecki1
New Contributor III

That worked.  I recreated everything and can add the related records.  I am unable to see the related records through the default popup and such but I can through the data table and via custom arcade based popup.

Still can't export as FGDB but I really don't have a reason too so I suppose it doesn't matter.  

Thanks for all your help.

0 Kudos
EricGardecki1
New Contributor III

khaled hassan‌ you mentioned "dropping" a relationship above.  Can you tell me how this is done?  I can't seem to figure it out.

I ran into some sort of issue with the related table so i want to reverse everything.  I need to remove the relationship and then remove the related table and start over.  I do not want to have to delete the service entirely and start over completely. 

I tried using the updateDefinition and deleteFromDefinition and everything I do just seems to stay there anyway after submitting.

What I tried to do was when adding the related table, include the fields for edit/create/editor/creator.  But doing so seems to have messed things up so I want to revert back to a more simple related table.  Unless you can tell me what I may have messed up with adding those fields?  Here is what I used:

{
"layers" : [
{
"name" : "Maintenance",
"type" : "Table",
"editFieldsInfo" : {
"creationDateField" : "CreationDate",
"creatorField" : "Creator",
"editDateField" : "EditDate",
"editorField" : "Editor"
},
"editingInfo" : {
"lastEditDate" : " "
},
"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" : "esriFieldTypeInteger",
"actualType" : "int",
"alias" : "FID",
"sqlType" : "sqlTypeInteger",
"length" : 4,
"nullable" : false,
"editable" : false,
"domain" : null,
"defaultValue" : null
}
]
}
]
}

Can you assist?

Thanks!

0 Kudos
KhaledHassen
Esri Contributor

Did you try deleting the table directly? deleting the table will also dropping any relationship it has with other layers.

Thanks

Khaled

0 Kudos
EricGardecki1
New Contributor III

via deleteFromDefinition?

Last time I tried I ended up with 2 relationships so I thought there was a better way but I can try again.

Do you see anything wrong with my JSON for adding the related table with editing tracking?  I don't know why the relationship isn't working and that is the only thing I have changed this time around.  I really wanted it to auto-create the date of edit so I didn't need the users to have to enter the date manually.

0 Kudos
KhaledHassen
Esri Contributor

Yes on the service (not the layer) deleteFromDefinition.

You will need to pass something like:

{

   "layers" : [

  {

      "id" : <tableId>

  }

 ]

}

BTW: Editor tracking is added at the service level. When you create a feature service, you will need to specify:

{

    ...

    "editorTracking" : {

      "enableEditorTracking"  : true

     ..

}

So editor tracking it is a system property on the service and you do not really  need to add anything on the layer for edit fields as long as you enable this on the service.

Khaled

0 Kudos
EricGardecki1
New Contributor III

I removed the layer and readded.  I'm still having my same issue.

When I try to add a related record in a web app, the window just seems to hang and I can't hit the "+".

In Collector, when I try to add a new record to related table, it simply says "Update Failed"  "Updates could not be sent".

Any suggestions?

0 Kudos
KhaledHassen
Esri Contributor

Can you share the service url? I can take a look.

0 Kudos