Attribute Rules: NextSequenceValue in a file database environment.

5701
25
Jump to solution
01-30-2020 06:44 AM
by Anonymous User
Not applicable

Attempting to create sequential IDs for managing above ground assets.

I successfully create the database sequence and have been working with two scripts. 

1.) Returns zeros in the FID field

--------------------------------------------------------------------------------------

var FID = $feature.FID;
($feature.FID == 1)
return "SP-" + NextSequenceValue("Traffic_SignalPole_ID")

--------------------------------------------------------------------------------------

2.) The FID values remain Null

----------------------------------------------------------------------------------------

var FID = $feature.FID;
(FID == 1)
return "SP-" + NextSequenceValue("Traffic_SignalPole_ID")

----------------------------------------------------------------------------------------

If is put an "if" before the second line regardless, the field value will be null.

Also when I check the table in arc catalog is shows that the sequence is adding to the database table, but is still not being appended to the feature its self.

0 Kudos
1 Solution

Accepted Solutions
RobertKrisher
Esri Regular Contributor

I'll make some assumptions about the questions you didn't answer (it's an immediate calculation rule configured to fire on insert).  Does your feature have a default value set on the field?  Try adding logic to the check so it looks for empty OR your default value.

if(isempty($feature.FID) || $feature.FID=="0") //If the field is empty or has the default value
return concatenate("SP-",nextsequencevalue("Traffic_SignalPole_ID")); //calculate a new id
else //otherwise
return $feature.FID //return the original value

View solution in original post

25 Replies
RobertKrisher
Esri Regular Contributor

Let's take a look at the expression.  I'm assuming this is some kind of immediate or batch calculation rule, which means that every time this expression fires the value returned from it will replace the value in your ID field.

It looks like you're trying to add in a test to see if the value is already populated, but because the statement isn't included in an if statement that means that it isn't controlling logic at all.  Here is an example of an expression that will only calculate a new sequence value if the field is empty.  In this case I assigned it as an immediate calculation rule on the "my_id" field.

if(isempty($feature.my_id)) //If the field is empty
return concatenate("SP-",nextsequencevalue("Test")); //calculate a new id
else //otherwise
return $feature.my_id //return the original value

Here's a screenshot of a few features I created using this rule.

Features Creating Using Expression

by Anonymous User
Not applicable

Would I need to create a new database sequence, since I have made many attempts as shown in the ArcCatalog table screenshot.

After using the script you proved I am still getting "0" in the FID field, but the sequence counter in the catalog table continues to increase?

0 Kudos
RobertKrisher
Esri Regular Contributor

Let's just focus on the geodatabase testing first, that way you can work out all the issues locally before pushing it all to enterprise.

Can you include the new expressions you're now using (with your field / sequence names) along with additional information about how the rule is configured?  It is just assigned to fire on insert? update?

0 Kudos
by Anonymous User
Not applicable

1.)

-------------------------------------------------------------------------------------------------------------------------------

if(isempty($feature.FID)) //If the field is empty
return concatenate("SP-",nextsequencevalue("Traffic_SignalPole_ID")); //calculate a new id
else //otherwise
return $feature.FID //return the original value

--------------------------------------------------------------------------------------------------------------------------------

2.)

--------------------------------------------------------------------------------------------------------------------------------

if(isempty($feature.FID)) //If the field is empty
return "SP-"+nextsequencevalue("Traffic_SignalPole_ID"); //calculate a new id
else //otherwise
return $feature.FID //return the original value

----------------------------------------------------------------------------------------------------------------------------------

The field is: FID

Only assigned to fire on insert.

The rules is an immediate calculation.

0 Kudos
RobertKrisher
Esri Regular Contributor

I'll make some assumptions about the questions you didn't answer (it's an immediate calculation rule configured to fire on insert).  Does your feature have a default value set on the field?  Try adding logic to the check so it looks for empty OR your default value.

if(isempty($feature.FID) || $feature.FID=="0") //If the field is empty or has the default value
return concatenate("SP-",nextsequencevalue("Traffic_SignalPole_ID")); //calculate a new id
else //otherwise
return $feature.FID //return the original value

by Anonymous User
Not applicable

The FID field data type is "Long", with the concatenate function is this okay or would it need to be changed to "String" to accommodate for the addition of text characters to the field values?

0 Kudos
by Anonymous User
Not applicable

I changed the data type for the FID field to "String"  and after using the script you provided 

if(isempty($feature.FID) || $feature.FID=="0") //If the field is empty or has the default value
return concatenate("SP-"+ nextsequencevalue("Traffic_SignalPole_ID")); //calculate a new id
else //otherwise
return $feature.FID //return the original value

The FID field is populated with values, but to my knowledge so far they seem to be random numbers. The positive thing is that it is returning values, now I am just trying to figure out how / where in the script this may be happening.

Also on a weird note, now when I create new features, there do not display, but are still selectable.

See attached.

0 Kudos
by Anonymous User
Not applicable

Robert,

After some tinkering I was able to successfully populate unique IDs using this script.

--------------------------------------------------------------------------------------------------------------------------------------

if(isempty($feature.FID)) //If the field is empty or has the default value
return concatenate("SP-" + nextsequencevalue("Traffic_SignalPole_ID")); //calculate a new id

--------------------------------------------------------------------------------------------------------------------------------------

RobertKrisher
Esri Regular Contributor

Nice!

0 Kudos