Select to view content in your preferred language

Help needed: arcade expression for attribute rule

210
7
Jump to solution
a week ago
christlmistl
New Contributor II

Dear community,

I have two attributes:
1) gebnr (this is the number of the studied field, le.g. 1 or 135...)
2) ID (this is the number of the studied field filled up to four digits, e.g. 1 -> 0001 or 135 -> 0135...)

I'd like to automatize the filling of the ID-attribute. I've tried to code a attribute rule, that says if
- gebnr < 10 then ID=000gebnr
- gebnr >=10 and gebnr<100 then ID=00gebnr
- gebnr>=100 and gebnr<1000 then ID=0gebnr
- gebnr>=1000 then ID=gebnr

My coding for ID looks like this now but it doesn't work (I have no experience in arcade at all):
var gebnr = $feature.GEBNRA
var ranking = When(gebnr < 10, Concatenate(000,gebnr), gebnr >=10 && gebnr < 100, Concatenate(00,gebnr), gebnr >= 100 && gebnr < 1000, Concatenate(0,gebnr), gebnr >= 1000, gebnr,-1);

Any ideas?

(Please, don't ask why these redundant attributes are necessary, it's German bureaucracy 😄 )

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisFox
Esri Regular Contributor

You can use the Text function for this:

return Text($feature.GEBNRA, '0000');

View solution in original post

7 Replies
ZachBodenner
MVP Regular Contributor

Could you please give a little more information about what you mean by "doesn't work"? Do you receive an error message? Are the returned values incorrect?

0 Kudos
christlmistl
New Contributor II

doesn't work means, that if I create for instance a new polygon and enter the gebnr = 1, the ID attribute stays at <NULL>

0 Kudos
ZachBodenner
MVP Regular Contributor

Can you show a screenshot of your attribute rule? 

0 Kudos
Dan_DMR
New Contributor III

What is the datatype for the ID field?

0 Kudos
ChrisFox
Esri Regular Contributor

You can use the Text function for this:

return Text($feature.GEBNRA, '0000');
RPGIS
by
Regular Contributor

@christlmistl 

@ChrisFox answer is the simplest solution to your problem. I would suggest for you to also research the 'console' function which will enable you to see the result in the messages.

0 Kudos
christlmistl
New Contributor II

Thank you all for your help! @ChrisFox answer solved the problem 🙂

0 Kudos