Adding a record to a related table?

651
3
07-31-2018 11:13 AM
KyleSchultz1
New Contributor II

Is it possible through QML to add a record to a related table? 

My example is I have a table with a bunch of assets located in a Water Treatment Plant.  I created  a related table in Arc Catalog and have it published as a feature service(along with my assets).  I want be able to query a record(using the barcode scanner) and add a record to the related table. 

So for I have the barcode side of things set up but I'm only finding information on querying a related table not adding to a related table.

0 Kudos
3 Replies
nakulmanocha
Esri Regular Contributor

Yes, Related Table is also a Feature Layer. Hence editing, adding or updating records in the Related Table is no different from editing,adding or updating a normal Feature Layer. Please use the same approach to add records as shown in Add & Delete features minus the geometry ( as I suspect your Related Table may not have any geometry associated).

Few steps here

// You will be using the ServiceFeatureTable.createFeature( <pass the attributes>) to create the Feature where ServiceFeatureTable will be your related Table

// Then you relate new feature to origin feature using feature.relateFeature()

// Finally, add new feature to related table

// Finally, perform applyEdits()

0 Kudos
KyleSchultz1
New Contributor II

I removed my original comment because after some work I got  a lot further now than I was

It's coming back with the record in the related table.  But my attributes I'm sending across are returning null

                 var featureAttributes = {"barcode" : "0000-TEST", "asset" : "test"};
                           var featureNew = relateTable.createFeature(featureAttributes);
                           features[0].relateFeature(featureNew)
                           relateTable.addFeature(featureNew);
                           relateTable.applyEdits();
0 Kudos
MKa
by
Occasional Contributor III

Did you ever get this to work?  I am stuck on this exact thing?  I have a related notes table to my parent Feature Layer.  The table represents various notes taken on the parent Feature layer.  Every time I try and create a blank feature it comes back as null?  Do the createFeatureAttributes all have to be accounted for or something, meaning that we need GlobalID too?  In my below code my noteFeature is always null after the createFeature line

notefeatureAttributes = {"1" : 1, 2 : 2};
var notesTable = app.fieldNoteTable; //QmlServiceFeatureTable
var noteFeature = notesTable.createFeature(notefeatureAttributes); //NULL Featrue?

My noteFeature above is null after that line

0 Kudos