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.
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);
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.
Solved! Go to Solution.
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.
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.
Hi David,
Many thanks for your advice & tips. Good to know I'm not the only one who has encountered this issue.