Set an attribute if another attribute is found in a SQL table?

516
1
06-03-2021 06:04 AM
LLCCG
by
New Contributor III

Is it possible to create an attribute rule that would set a flag if a different attribute is found in a SQL table?

I have a feature class which each has a unique ID #. Could I set an attribute rule to look for that number in a SQL table, and if it exists, set a flag?

If so, how would I do that?

 

 

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

I fear I don't really understand what you're asking.

Here's what I understood: You have a feature class FC with the fields FC.UniqueID and FC.Flag and a table TBL with the field TBL.UniqueID. If you add or edit a feature in FC, you want to set FC.Flag depending on whether FC.UniqueID is in TBL.UniqueID. Correct?

This would be a way to do it:

// Calculation rule
// Field: Flag
// Triggers: Insert, Update

// load the table
var table = FeatureSetByName($datastore, "DatabaseName.TableOwner.TableName", ["UniqueID"])

// filter table by UniqueID
var uid = $feature.UniqueID
var filtered_table = Filter(table, "UniqueID = @uid")

// return 0 if the feature's UniqueID is not found in the table
if(filtered_table == null || Count(filtered_table) == 0) {
  return 0
}
// return 1 if the feature's UniqueID is in the table
return 1

 


Have a great day!
Johannes