Select to view content in your preferred language

Add Feature for Table Returns success, Add Result when returned for relationship doesn't

128
1
Jump to solution
a week ago
Labels (1)
TimWestern
Occasional Contributor

So I have a bit of a puzzling behavior.

We have been working on a custom widget that allows us to collect data from a form, and then add it to a table in AGOL.    The edit is conducted via apply edits sending the new feature with 'add-feature' as part of the data sent.

When it returns it returns as expected and that table entry now appears:

TimWestern_0-1718830690546.png

 



This table also has a relationship with the ID Field used for the parcel, so I have to make sure the relationship is created in code.   I use a similar service call (just different feature data going to the relationship and it returns:

TimWestern_1-1718830745017.png


At first I thought it must have worked because I got a globalID back, but it doesn't include success= true and error is returned = null.  Does this mean the add failed? Or is it possible I've done something else wrong?

The table and relationship are in the same service (and are also in a map that uses the service inside of it in case that matters).

Any thoughts?


 

0 Kudos
1 Solution

Accepted Solutions
TimWestern
Occasional Contributor

I can confirm that I have found a solution.  There were a number of issues in my code which I won't share here, but if your relationship 'table' has addFeature and applyEdits you should be able to write to them as you would any other table or layer.  This was not clear from  the documentation, and so i wondered if it was possible, but it turned out I had a bit of a context problem in my code.

If you get the Feature ID (the number in the path) for the first layer/table, and want to write to the other one, you gotta make sure that you identify, 1 the correct layer/table and its index when you try to write its expected data.  SOmehow I was passing the first layerIndex in error, and didn't catch it because in a generic sense it looked correct, (but it wasn't correct), once I added that relationshipLayerId, it wrote out no problems!

This may sound like obvious advice, but when you get into many-to-many m-2-m relationships, you may end up with three layer/table identifiers and its very easy to miss pass one of the ids.  So save yourself many hours of effort and name your methods that call into other labels with a different more clear index parameter name so its easier to catch in the future.

View solution in original post

0 Kudos
1 Reply
TimWestern
Occasional Contributor

I can confirm that I have found a solution.  There were a number of issues in my code which I won't share here, but if your relationship 'table' has addFeature and applyEdits you should be able to write to them as you would any other table or layer.  This was not clear from  the documentation, and so i wondered if it was possible, but it turned out I had a bit of a context problem in my code.

If you get the Feature ID (the number in the path) for the first layer/table, and want to write to the other one, you gotta make sure that you identify, 1 the correct layer/table and its index when you try to write its expected data.  SOmehow I was passing the first layerIndex in error, and didn't catch it because in a generic sense it looked correct, (but it wasn't correct), once I added that relationshipLayerId, it wrote out no problems!

This may sound like obvious advice, but when you get into many-to-many m-2-m relationships, you may end up with three layer/table identifiers and its very easy to miss pass one of the ids.  So save yourself many hours of effort and name your methods that call into other labels with a different more clear index parameter name so its easier to catch in the future.

0 Kudos