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.
Solved! Go to Solution.
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.
If you need more clarification please let me know,
Best Regards,
Amir Sarrafzadeh Arasi
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.
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.
If you need more clarification please let me know,
Best Regards,
Amir Sarrafzadeh Arasi
Amir, that absolutely worked for my use case, thank you for your input!
My Pleasure 😉