Hi everyone,
i'd like to know if its possible to concatenate an original GlobalID field with another numeric one.
I'm trying to create a field(COD_ID) that contain $feature.GlobalID + $feature.CODFAB = COD_ID
Thanks so much!
thai mota
concatenation requires that the destination field be text.
When concatenating numbers, they have to be converted to text
in python
str(1) + str(2)
will yield 12
or use
"{}_{}".format(1, 2)
to get "1_2"
It looks like you may be doing this in Arcade. Here is an attribute rule that I use to concatenate two fields in my streets feature class:
// This rule will calculate the alias name field by concatenating the an_name and an_postdir fields....
// Specify the fields to concatenate
var values = [$feature.AN_NAME, $feature.AN_POSTDIR]
var combined_value = [];
// Loop through the field values and test if they are null or empty strings
// If they are not null or empty add them to an array
for (var i in values) {
var value = values[i];
if (IsEmpty(value)) continue;
combined_value[Count(combined_value)] = value
}
// Return the field values concatenated with a space between
return Concatenate(combined_value, " ");
It's always a good idea to test for empty or null value fields to avoid an errors when you least expect them.
Hi @thainamota ,
Can you explain a little bit more about why you want to concatenate these values?
It is possible to concatenate a GUID and a text as shown in the simplified example below:
var globalid = Guid();
var sometext = "abc";
return Concatenate([globalid, sometext], ' ');
This will return:
{5429dd99-754a-4388-868a-c4436624b705} abc
Please take into account the comments by @JoeBorgione about null values.
Hi guys thanks for yours answers @DanPatterson @JoeBorgione @XanderBakker
Unfortunately what i’m trying to do became complicate. I’ll try explain
I want to create a concatenate field ( other 4 fields). Then, at the same introduce an attribute rule for each field
So, my feature has:
cod_fab that is already compilate
cod_seq for what I do calculate field –> Sequential number from 10.000 interval 1
cod_alfa with two letters, the same for all records (calculate field )
cod_unique concatenate field (cod_fab + cod_alfa + cod_seq)
The attribute rules that I want to create for fields above is :
a. If cod_fab is null or zero return 00000
b. Nextsequencevalue, in cod_seq, from 54.398
c. Compilate PP in cod_alfa field
d. Concatenate in cod_unique: cod_fab (its numeric field - 5 digits), cod_alfa(PP) e cod_seq
The result should be something like that 36049PP54394
My problems are:
1-create and run all these attribute rule
2- Implement all these attribute rules in feature that has more than 44.400 geometries
3 - Some records have cod_fab zero, so I try to put 00000 in cod_unique to complete the field.
Yours advices will be very very welcome !!
Thanks and sorry for delay (in the last hours I try to do alone with many errors and no success)
thaina mota
So we are not dealing with an actual global id field anymore?
You mention that you want an attribute rule for each field. When do you want these rules to fire? Are you adding new features to this layer, or do you want to validate the existing values and update them? Depending what you are doing, I suggest you take a look at the online help that describes the difference between calculation and validation rules.
You also mention a sequence. You can add a database sequence that starts at any value and increments by any value. Typically these are used when adding a new feature, but I think you could write a validation rule such that if that field is <null> or 0, return the next sequence value
Is the cod_alfa always going to be 'PP' if so, I would simply calculate that field to equal 'PP'. If you are adding features and want 'PP' to be the default, I suggest you use a domain for that.
I tinkered around a bit in the arcade ' playground ' and got the following code working:
var values = [0, 'PP', 1234]
var combined_value = [];
for (var i in values) {
var value = values[i];
if (value == 0) {
value = "00000"
}
combined_value[Count(combined_value)] = value}
Console(Concatenate(combined_value, ""));
The Console() function prints the value of the concatenated_value:
Hopefully this helps a bit.
Oh yes maybe is better change the title.
So,
1- I'd to validate the values and to fire the same rules when i add a new feature or divide a polygon.
2-I noted that is necessary to have a globalId field (even if I don't use it) to use the 'nextsequencevalue'
3- And, yes, the cod_alf will be always 'PP'.
Thanks @JoeBorgione , i'll follow yours advices
let you know
Grazie!
In order to deploy address rules on a feature or table record, they must be assigned Global IDs. You accomplish this with Add Global IDs. Global IDs are generated and maintained behind the scenes by the geodatabase itself. So if you copy or otherwise move the records to another geodatabse, the global ids will change.