I am calculating a field in Field Maps by checking data in a table related to the layer. The problem is that if there are no related values in the table the expression evaluates to an error which prevents the data from being submitted. What I want to do is assign a string value of 00 to the field if there are no records in the related table but my code fails instead of assigning that value. I think what is happening is that the FeatureSetByRelationshipName function returns an error if there aren't related records and the part of my function that returns 00 is not evaluated. There isn't, as far as I know, an on error type function in Arcade that I could use to check if the function FeatureSetByRelationshipName evaluates to an error. If there was it would be a simple matter of checking that then assigning 00 if there is an error. The !IsEmpty in my code doesn't work because the function doesn't return null for the variable it returns an error. Does anyone know how I can get around this?
var relatedFeatures = FeatureSetByRelationshipName($feature, "RecordType2", ["Rep"], false);
if (!IsEmpty(relatedFeatures) && $feature.EventType == 'Sampling') {
return text(count(relatedFeatures),"00");
} else {
return '00';
}