Select to view content in your preferred language

How to conditionally check if a field exists using Arcade label profile

1106
2
08-31-2023 01:44 PM
Labels (1)
JPrescott
New Contributor II

Hello, Are there any Arcade methods in the Labeling profile for checking if a field exists?  I am working on consolidating many Arcade labeling expressions into one, and some of the layers this new expression have fields which other layers do not.  When these fields are present, they should be used for labeling.  I need a method to conditionally check if the field exists in a particular feature or not before assigning it to a variable.  I have tried several methods which work in Pro, but so far, all of these methods are not available in the labeling profile, and so cannot be used in Portal.  For example, I have tried using Haskey(), but the labeling renderer does not load all fields, and therefore the field names I require are not present in the $feature "attribute" dictionary.  Using Expects() would fix this issue, but Expects() is not available in the labeling profile.  There were also possible methods in the Domain() functions, but those are also not available in the label profile.  Below is an example of how I tried a conditional statement using Haskey() (which did not work because Expects() is not in the label profile, and without Expects(), Haskey() can't find the field name because not all the fields are loaded by the renderer).

var field_might_be_present = 'field_name'
Expects($feature, 'field_name', 'other_field_name') 
if(Haskey($feature, field_might_be_present)){
    var typeassetnum = $feature[field_might_be_present]
}
else
{
    var typeassetnum = ''
}

I appreciate guidance anyone might be able to provide.

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

I was responding to this thread that was using HasKey and noticed that it acts peculiarly in the Labeling profile. Initially, it evaluates at False, even if the field exists. However, after zooming in and out several times, it started evaluating as true. If I saved the map and reopened it, it also evaluated as true.

0 Kudos
Amir-Sarrafzadeh-Arasi
Occasional Contributor

Dear JPrescott,

I hope you are doing well when reading this message,

Please check the below image, I hope that is exactly what you looking for.

If you check, I have a Field name which is 'city' in my featurelayer.

AmirSarrafzadehArasi_0-1699614054863.png

 

If you need more clarification please let me know,

Best Regards,

 

Amir Sarrafzadeh Arasi

Amir Sarrafzadeh Arasi