How to get Relationship Table with FeatureSetByName?

260
2
03-18-2024 01:34 PM
mtrinh
by
New Contributor

Hello,

I was hoping to get some help with my code. I am trying to use FeatureSetByName to get a certain Relationship Table of a M:N relationship. I want to get the table to implement my code so that, for whatever reason, if a unique identifier changes then it also changes accordingly in the Relationship Table so that nothing breaks. I tried looking on the forums but I can't even confirm if this function can be used to get a relationship table, but it seems to work for standalone tables.

More context: The long layer name is the name of the M:N Relationship Class and when I drag that onto the map it gives me the standalone M:N Relationship Table. The Relationship Table has the same name as the Relationship Class.

Here is my Error Code: 001841: The table was not found.

Here is my code: (sorry for the long layer names, doing tests before using the real layers)

if($originalfeature.AddressID == $feature.AddressID) {
}
else {
 

 var FS = FeatureSetByName($datastore, 'physicaladdressexportfeature_BuildingFootprintss', ['GlobalID', 'Address_ID'], false)
 var AddressID = $originalfeature.AddressID
 var relation = filter(FS, 'Address_ID= @AddressID')
 var updatelist = []
 var counter = 0


 if(relation == null) {
 }
 else {
  for(var x in relation) {
   updatelist[counter] = {
    'globalid': x.GlobalID,
    'attributes': {
     'Address_ID': $feature.AddressID,
    }
   }
   counter++
  }
  return {
   'edit': [{
    'className': 'physicaladdressexportfeature_BuildingFootprintss',
    'updates': updatelist
   }]
  }
 }
}

 

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

If you have a relationship set up between the feature layer and the relationship table, you can use that directly using FeatureSetByRelationshipName function to return the related records for a feature.

For example, this layer has several related tables.

service.png

This is the code to loop through the related records from the related table "DCGIS.SURDOCS" for the feature.

var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS");
for (var rec in related) {
  
}

 

0 Kudos
mtrinh
by
New Contributor

Hi thank you for commenting and trying to help out. I've tried using FeatureSetByRelationshipName but that just gives me the feature set that it is related to, not the Relationship Table, which is different from a related table. I'm trying to get a hold of the Relationship Table which is the table automatically created when creating a M:N Relationship Class. 

0 Kudos