Arcade Attribute Rule ignores current layer

211
2
Jump to solution
a month ago
DomHabron
New Contributor

Hi,

I'm using ArcPro 3.1.3 with an Advanced Licence with the data stored in a postgresql database accessed via sde.  

When adding a new feature to a point dataset I have an attribute rule to populate the ID field with the existing maximum id + 1.  I want the code to dynamically retrieve the current layer being worked on.  


This is the code that in theory should work:


var CurrentLayer = GetFeatureSetInfo($featureset).className;
var CurrentIdField = FeatureSetByName($datastore, CurrentLayer, ["mpd_id"], false);
var CurrentMaxId = Max(CurrentIdField, "mpd_id");
return CurrentMaxId + 1;

However, the rule will not validate in ArcPro & returns the 999999 error.

DomHabron_1-1712584901252.png

 

I've tested the value returned to 'CurrentLayer' by writing it to a separate text field, the value is: "geodatabase.gisdata.MPD_PIPE_CABLE_CROSSINGS".  

If I delete line 1 above and substitute the actual dataset name for 'CurrentLayer' in line 2 as follows:
var CurrentIdField = FeatureSetByName($datastore, "geodatabase.gisdata.MPD_PIPE_CABLE_CROSSINGS", ["mpd_id"], false);

DomHabron_0-1712584761175.png

then the code validates and runs producing the expected result.  However, ultimately I need to be able to dynamically reference several layers in order to find the max id and so don't want to hard code any dataset names. 

 
Does anyone know why the value of the variable CurrentLayer not read by the FeatureSetByName funciton?

I wondering if it could be a text case issue, so created a copy of my postgresql layer using all lower case characters, however this made no difference & returned the same error.  

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DavidSolari
Occasional Contributor III

I ran into a similar issue in the past and unfortunately there wasn't a workaround. To my understanding FeatureSetByName must take name of the table as a string literal or it'll create an error. I have to assume there's some hacky pre-processor nonsense that goes on with this function, either way you'll just have to type out the right name for every rule. If you're writing the rule multiple times you might want a script tool that uses Add Attribute Rule to save some time.

As an aside, that method of getting the max ID isn't optimal for large datasets, even with an index on the ID field. You may want to look into combining a database sequence with NextSequenceValue to get a new ID in constant time.

View solution in original post

0 Kudos
2 Replies
DavidSolari
Occasional Contributor III

I ran into a similar issue in the past and unfortunately there wasn't a workaround. To my understanding FeatureSetByName must take name of the table as a string literal or it'll create an error. I have to assume there's some hacky pre-processor nonsense that goes on with this function, either way you'll just have to type out the right name for every rule. If you're writing the rule multiple times you might want a script tool that uses Add Attribute Rule to save some time.

As an aside, that method of getting the max ID isn't optimal for large datasets, even with an index on the ID field. You may want to look into combining a database sequence with NextSequenceValue to get a new ID in constant time.

0 Kudos
DomHabron
New Contributor

Hi David,

Many thanks for your advice & tips.  Good to know I'm not the only one who has encountered this issue.

0 Kudos