Select to view content in your preferred language

Count Feature Class records using Attribute Rules

1461
3
Jump to solution
05-09-2023 05:25 AM
Mohamed_Gamal
Emerging Contributor

I created an attribute rule with the triggering event "Update" in an attempt to obtain the number of records for the feature class.

the code is this:

 

return{"errorMessage" : "An "+count(FeatureSetbyName($datastore, "Room"))}

 

whenever I update any records on the table, the count of records is the actual number plus one.

image.png

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

Guess I should have payed more attention to the original post.  I had Insert enabled on the tool, so was a bit different.

Even so, I was not able to reproduce with just update, and was still geting the correct count (testing with data from SQL server EGDB):

RhettZufelt_0-1683731224285.png

However, when testing with the same feature class/attribute rule exported to a FGDB feature class:

RhettZufelt_1-1683731297999.png

 

I am then consistently getting the actual count + 1 as you are seeing.  So, since they report different values from the same rule/data, just different sources, I'd suspect you have discovered yet another bug.

Might want to start a tech support request so that this issue might get addressed.

R_

 

View solution in original post

0 Kudos
3 Replies
RhettZufelt
MVP Notable Contributor

Maybe run the check geometry tool and see if there is a invalid geometry or something.

I get the exact count using your code in 2.9.3 and 3.1.1

R_

Actually, on second thought, I think it is working as expected.  If you have 8 values in there already, then try to add one, it should be number 9.  However, since it is showing as error message, it is what "would" be there if it were to create the feature (since feature isn't created on error).

Perhaps try updating the field instead of returning an erromessage and see if that "fixes" it:

count(FeatureSetbyName($datastore, "Room"))

R_

 

0 Kudos
Mohamed_Gamal
Emerging Contributor

Greetings, Rhett Zufelt

First of all, I appreciate your reply. There are no flaws in the records' geometry, which was your initial concern. It is therefore illogical for the case, I am displaying on this case to have nine records because I am updating one of them not adding a new one. The error message just informs me of the count's value before continuing with other procedures.

Before counting the records, I simply need to apply a filter, however, I'm not sure why this issue is occurring.

Count(Filter(FeatureSetbyName($datastore, "Floor"),"1 = 1"));

 

0 Kudos
RhettZufelt
MVP Notable Contributor

Guess I should have payed more attention to the original post.  I had Insert enabled on the tool, so was a bit different.

Even so, I was not able to reproduce with just update, and was still geting the correct count (testing with data from SQL server EGDB):

RhettZufelt_0-1683731224285.png

However, when testing with the same feature class/attribute rule exported to a FGDB feature class:

RhettZufelt_1-1683731297999.png

 

I am then consistently getting the actual count + 1 as you are seeing.  So, since they report different values from the same rule/data, just different sources, I'd suspect you have discovered yet another bug.

Might want to start a tech support request so that this issue might get addressed.

R_

 

0 Kudos