Select to view content in your preferred language

Arcade Expressions and Related Records count not working if no related record exists

987
3
Jump to solution
09-13-2023 06:21 AM
Labels (1)
LarryMcEvoy70
New Contributor II

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.

LarryMcEvoy70_0-1694609862984.png

When no related record exists its a totally different issue. the output flags an error and the console output stops at the count.

LarryMcEvoy70_1-1694610496871.pngLarryMcEvoy70_2-1694610545377.png

Even more confusing is the popup populates but is slow

LarryMcEvoy70_3-1694611134205.png

 

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

 

0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
  output = `There are ${relatedCount} surveys for this property:`;
  for (var rec in related) {
    output += `<br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
  }
}

return { 
	type : 'text', 
	text : output
}

console.png

 

View solution in original post

0 Kudos
LarryMcEvoy70
New Contributor II

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.

View solution in original post

0 Kudos
3 Replies
LanceKirby2
Occasional Contributor II

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).

0 Kudos
KenBuja
MVP Esteemed Contributor

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>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
} else {
  output = `There are ${relatedCount} surveys for this property:`;
  for (var rec in related) {
    output += `<br>&nbsp •  <a href="${rec.FILENETLINK}">${rec.DOCGUID}</a>`;
  }
}

return { 
	type : 'text', 
	text : output
}

console.png

 

0 Kudos
LarryMcEvoy70
New Contributor II

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.

0 Kudos