Select to view content in your preferred language

Arcade Expression pulling from Related Records

391
3
01-24-2023 12:56 PM
Labels (1)
CRBData1
New Contributor

Hi all I need some help!  This is my arcade expression which is resulting in all palms returning a 'Yes' value. Any clue what is wrong with my expression? Any help is appreciated.

Mahalo,

Meg

 

var reltbl = OrderBy(FeatureSetById($map, /* Individual Palm Damage Survey */ "Collector_Palms_9566"),"SurveyDate DES")
var cnt = Count(reltbl)

var sprdmg = ''
var borehls = ''
var inrfrnd = ''
var outfrnd = ''

if (cnt>0){
var info = First(reltbl);
sprdmg = info.SpearDamage;
borehls = info.BoreHoles;
inrfrnd = info.InnerFrondsDamaged;
outfrnd = info.OuterFrondsDamaged;

if(sprdmg == "No" && borehls == "No" && inrfrnd == "0" && outfrnd == "0"){
return "No"
}
if(sprdmg == NULL && borehls == NULL && inrfrnd == NULL && outfrnd == NULL){
return "Null"
}else {
return "Yes"
}
}

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Are the InnerFrondsDamaged and OuterFrondsDamaged fields numeric or text? If they're numbers, than your first if statement should be

if(sprdmg == "No" && borehls == "No" && inrfrnd == 0 && outfrnd == 0){

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Hard to tell, exactly, but the way this is written, your conditions have a few different "offramps".

  1. If no values exist in the related table, it wouldn't return anything.
  2. If those four fields are "No" or "0", it returns "No"
    • Are the second two fields really strings? If they are integers, write it 'inrfrnd == 0'. Checking an integer field being equal to a string will guarantee that nothing will ever satisfy the condition.
  3. If all the fields are null, it returns "Null". Nothing appears wrong with this condition, but you may want to try using IsEmpty(sprdmg) instead, on the off chance that a field has an empty string, which is not the same as a true null.
  4. Else return "Yes"

My guess is that maybe point 2 is evaluating strings / integers, so it's always missed, and maybe you have empty strings, so point 3 is being missed as well?

Any chance this layer is public? It's always easier to diagnose issues with access to the data.

- Josh Carlson
Kendall County GIS
0 Kudos
crbdata
Emerging Contributor

The two fields are strings and the other two are integers so I went with your suggestion writing it as infrnd == 0 instead. And even with just that first line of statement (removing the other lines) to test it, the value would result in Null so it must be a problem with that first line.  

I found that if I made a label with a similar arcade expression instead of in the pop up, this worked and shows what palms are currently damaged vs. not.  

 

Thank you all for your help and quick responses as well!

0 Kudos