Select to view content in your preferred language

adds and edits of parent and related tables

399
1
05-15-2023 10:02 AM
KPyne
by
Occasional Contributor

Hello everyone,

I am rather new to the REST API and have been searching for an answer but no luck so far...

I have two asset layers related to an Inspection table (Junction-One to Many-Inspection, Device-One to Many-Inspection) within the same hosted feature layer in AGOL.  I am using webhooks to trigger applyEdits to update the parent feature (of either layer, never both) AND add a new Inspection record to the related table. 

I have the GlobalID of the parent records related to an "InspectionID" of the related table.

However, when I request a new Inspection record, it fails because the "InspectionID" only exists in 1 of the 2 parent layers. If I only relate 1 of the 2 parent layers by GlobalID, it works correctly - but then I can no longer submit new records for the other layer since it is no longer related by GlobalID.

I have tried relating by an alternate field such as AssetID, but all attempts end up the same - as soon as I request a new record via GlobalID, it fails because that GlobalID only exists in 1 of the 2 tables.

The exact error:

The INSERT statement conflicted with the FOREIGN KEY constraint "REL_FK_UPDM_ASSET_INSPECTION_1". The conflict occurred in database "db_14812", table "user_14812.UPDM_GAS_DEVICE", column 'GlobalID'. The statement has been terminated.

 

Am I going about this all wrong? Is there a cleaner way to update a related table without it worrying about if there is a matching record?

 

0 Kudos
1 Reply
KPyne
by
Occasional Contributor

I have been working on this issue for a few days now and of course after posting the questions I found my own solution. Feel free to remove post or leave here for any future reference:

I had to make ALL relationship keys a field other than GlobalID. That way I could still push updates using GlobalID without causing a relationship error. I still do not fully understand the above error and if I am performing the correct steps, but it is working now.

0 Kudos