I have been forced into using arcade expressions to HTML format data as part of this I have to use some related records. The relationship between the feature class and the related table is one to many or none as such some of the features do not have a related record.
for debugging purpose I have taken the relationship part out into into a separate expression what I have at moment is this
var x=FeatureSetByRelationshipName($feature, "drainageIAforms_1",['FluvfloodRisk'],false)
Console(x)
console(IsEmpty(x))
console(Count(x))
console(first(x))
var result=''
if (Count(x)>0) {
var y=first(x)
result = y.FluvfloodRisk
}
else {
result= 'No Data'
}
return {
type : 'text',
text : result
}
works perfectly if there is a related record there, I get the expected return and the console populates as you would expect and it takes a reasonable amount of time to return.
When no related record exists its a totally different issue. the output flags an error and the console output stops at the count.
Even more confusing is the popup populates but is slow
I thought the count of the feature set was the way to check if there were records is there something I am missing.
Thanks in Advance if anyone has a solution
Solved! Go to Solution.
I used a similar methodology on a popup and don't experience a lag or problems in the console
var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS", ['FILENETLINK', 'DOCGUID'], false);
var relatedCount = count(related);
var output;
if (relatedCount == 0) {
output = `<p>There are no surveys for this property.<\p>`;
} else if (relatedCount == 1) {
var rec = First(related);
output = `There is 1 survey for this property:
<br>  • <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
output = `There are ${relatedCount} surveys for this property:`;
for (var rec in related) {
output += `<br>  • <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
}
}
return {
type : 'text',
text : output
}
Solved: Re: Arcade error when accessing empty feature set - Esri Community
Just in case anyone comes across this the problem was already solved in the link above, I had not notice that I had nulls within my foreign key once I implemented a check for it job was golden thanks @KenBuja if you had not shown me it working I would have just left it as the result was coming in.
This one had me stumped a couple of weeks ago. As you pointed out the related record you are testing against has no match. Since it can't find a match, even though it looks like an empty feature set is returned it's more like a null and it can't perform that function on a null value. I think what I would do is instead of using Count(x) > 0 use !IsEmpty(x).
I used a similar methodology on a popup and don't experience a lag or problems in the console
var related = FeatureSetByRelationshipName($feature, "DCGIS.SURDOCS", ['FILENETLINK', 'DOCGUID'], false);
var relatedCount = count(related);
var output;
if (relatedCount == 0) {
output = `<p>There are no surveys for this property.<\p>`;
} else if (relatedCount == 1) {
var rec = First(related);
output = `There is 1 survey for this property:
<br>  • <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
output = `There are ${relatedCount} surveys for this property:`;
for (var rec in related) {
output += `<br>  • <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
}
}
return {
type : 'text',
text : output
}
Solved: Re: Arcade error when accessing empty feature set - Esri Community
Just in case anyone comes across this the problem was already solved in the link above, I had not notice that I had nulls within my foreign key once I implemented a check for it job was golden thanks @KenBuja if you had not shown me it working I would have just left it as the result was coming in.