Attribute Rule - Generate ID - Establishing Width

895
6
Jump to solution
02-15-2021 02:18 PM
Labels (3)
HeidiHarris
New Contributor III

In Desktop's old Attribute Assistant, you could create a generate ID rule that could keep a consistent width to the integer portion of the ID.  So you could have a width of 7 and if the sequence was only 3 numbers, it would add 4 zeros to the left.

 

I'm trying to  migrate a client from Attribute Assistant to Attribute Rules in Pro and I cannot find a way to accomplish this same functionality.  In the screenshot you can see how their IDs generated in ArcMap/Attribute-Assistant vs. how I can get them to generate in Pro using the following:  

return "ADA-" + NextSequenceValue ("ADA")

where I've named the generated sequence "ADA"

HeidiHarris_0-1613426795346.png

What arcade can I add in to that expression to maintain that forced width?

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

Haha, I didn't even think of the Text() function...

Disregard the above, use this instead:

return "ADA-" + Text(NextSequenceValue("ADA"), "0000000")

Have a great day!
Johannes

View solution in original post

6 Replies
MehdiPira1
Esri Contributor

Hi @HeidiHarris ,

In ArcGIS Pro, click on the feature class layer you want to add attribute rules to in TOC and then click Data tab > Attribute Rules in Design.

MehdiPira1_0-1613439763133.png

In Attribute Roles windows you can add a Calculation Rule in Arcade like:

concatenate('ADA-000',$feature.<your fc field>)

MehdiPira1_1-1613440031339.png

I hope that helps.

Cheers

Mehdi

======================================================================

Please give a like if helpful and Accept as Solution if it's answered your query.

 

 

 

0 Kudos
HeidiHarris
New Contributor III
Hi! Unfortunately that won’t quite work as we need the integer length to stay at 7 regardless of if the next sequence value is three (999) or four (1000) integers lonv
0 Kudos
MehdiPira1
Esri Contributor

@HeidiHarris ,

Then you need to use something similar to this:

var ADA_id = split($feature.<your ADA field>, "-")[1]
If (Count(ADA_id ) == 4) {
   return concatenate('ADA-000',ADA_id)
}

else {
   If (Count(ADA_id ) == 3) {
      return concatenate('ADA-0000',ADA_id)
 } 
   else {

      return ADA_id

 }}

======================================================================

Please give a like if helpful and Accept as Solution if it's answered your query.

 

 

0 Kudos
JohannesLindner
MVP Regular Contributor

 

// next sequence value as string
var ada = "" + NextSequenceValue("ADA")

// there doesn't seem to be a while loop in Arcade,
// but we can fake one with a for loop...
for(var i = 0; i < 100; i++) {
  if(Count(ada) >= 7) {
    break
  }
  ada = "0" + ada
}

return "ADA-" + ada

 


Have a great day!
Johannes
0 Kudos
JohannesLindner
MVP Regular Contributor

Haha, I didn't even think of the Text() function...

Disregard the above, use this instead:

return "ADA-" + Text(NextSequenceValue("ADA"), "0000000")

Have a great day!
Johannes
HeidiHarris
New Contributor III

This worked perfectly!  Thank you!

0 Kudos