Concatenate field values with Arcade in field calculator

6128
5
09-08-2020 07:52 AM
EkremCanli2
New Contributor III

I have 5 text fields, each holding a name. In AGOL I've created a new field that should hold all respective field values in a string (I used 2 for loops to count the number of non-empty fields; if there's just 1 populated field, I don't need a comma separator). Testing my Arcade expression in the console was successful, the output is correct, but it simply won't write to my newly created field, although it says calculating fields > committing > inserting when confirming my Arcade expression window with OK. It just stays empty.

Here's my code and my console output:

How do I write my output into my newly created field on which I applied the field calculation?

Tags (1)
0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

Hi Ekrem Canli ,

I would probably use the following expression, but it is a bit strange that he expression works as test in the GUI, but does not return any result when calculating. 

// point this to the field in the $feature
var UAV_arr1 = [Null, "DJI Inspire 3", "DJI Mavic Air 2", Null, "DJI Phantom 4 Pro V2.0"];

// remove null elements from array
var UVA_arr2 = [];
for (var i in UAV_arr1) {
    if (!IsEmpty(UAV_arr1[i])){
        UVA_arr2[Count(UVA_arr2)] = UAV_arr1[i];
    }
}

// test to see if you have values in the array and return the result
if (Count(UVA_arr2)>0) {
    return Concatenate(UVA_arr2, ", ");
    
} else {
    // define what to return if you don't have any values
    return "";
}

Returns:

DJI Inspire 3, DJI Mavic Air 2, DJI Phantom 4 Pro V2.0

Change the test to (only one element):

var UAV_arr1 = [Null, Null, "DJI Mavic Air 2", Null, Null];

Returns:

DJI Mavic Air 2

And without any values:

var UAV_arr1 = [Null, Null, Null, Null, Null];

Returns an empty string...

0 Kudos
EkremCanli2
New Contributor III

I've tried your code, it worked in the Arcade Calculator, it again said calculating fields > committing > inserting, but the fields still stay empty. Am I missing a command to actually write the output of the console into the fields when using the calculate fields tool on AGOL? Whatever I do, it's always empty:

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ekrem Canli ,

This should work. Not sure if there is something in the configuration of the data or the type of source that prevents the data from being updated. If you simplify the calculation just returning something like "test", does this work? (to rule out that you cannot use field calculations on the data). I assume that the output field is a Text field and the width is sufficient to hold the result?

0 Kudos
EkremCanli2
New Contributor III

Hi Xander Bakker‌...I think it has to do with the fields having domains. When I just return 'test', my new, empty field is correctly populated with the string test. When I run 'return DomainName($feature,"UAV1")' it shows the correct result below in the results, but when I confirm with OK to run the arcade calculator, my field remains empty... Any further idea?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ekrem Canli ,

Thanks for testing this. To me this sound as something that should be reported to support. You should be able to use the DomainName function in the expression. One could do an additional test using the actual domain code of the feature and using the Domain function to see if you can extract the name from that domain, but I don't think that has a lot of potential. Please report the issue to support to have this fixed.