Select to view content in your preferred language

Arcade Field Calculation Error

439
3
Jump to solution
04-12-2023 12:26 PM
DylanW_TOC
New Contributor II

I'm struggling to complete a field calculation using Arcade. I'm trying to calculate a field in table 1 based on a field from table 2. Both tables exist in the same file geodatabase. 

 

 

 

 

var commericalLine = FeatureSetByName($datastore,'CommericalLine_Table')

if ($feature["FACILITYID"] == commericalLine["FACILITYID"]) {
    return 1
}

else{
   return Null 
}

 

 

 

 

When I go to validate the expression, I receive the following error message:

Invalid Expression.

Error on line 3

Dictionary type expected.

 

Any suggestions on how to resolve this?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Your code was taking so long since you were cycling through all 28K features in table 2 for each feature in table 1. And it wasn't finding the correct output, since you were comparing the first record in Table 2 to your feature, instead of the looped feature in table 2 ("feat.FACILITYID" instead of "f.FACILITYID").

Give this a try. It filters table 2 by the FACILITYID of the feature in table 1. If there is a corresponding record in table 2, then it return 1. Otherwise, it returns null (which isn't explicitly needed in this script in my testing)

var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var id = $feature.FACILITYID
var filteredTable = Filter(commericalLine, "FACILITYID = @ID")
if (Count(filteredTable) > 0) return 1;

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

FeatureSetByName returns a FeatureSet, not a single feature. You have to get a feature from that FeatureSet to do the comparison. If you're expecting there to be one feature, then you can use First to return that feature. If there are multiple features in that FeatureSet, you'll have to loop through them or use a Filter to get a specific one. If you use a Filter, remember that function will also return a FeatureSet and you'll need to use First to get the single feature.

 

var commericalLine = FeatureSetByName($datastore,'CommericalLine_Table')
var feat = First(commercialLine);
if ($feature["FACILITYID"] == feat["FACILITYID"]) {
    return 1
}
else{
   return Null 
}

 

0 Kudos
DylanW_TOC
New Contributor II

Thanks for the response, Ken. I tried out the code below, but it only matched one record (out of 28k) when it should have matched 3k 

var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var feat = First(commericalLine)

for (var f in commericalLine){
    if ($feature.FACILITYID == feat.FACILITYID){
        return 1
    }
}

 

Another thing, it took over 10 minutes to complete this calculation does that sound right?

0 Kudos
KenBuja
MVP Esteemed Contributor

Your code was taking so long since you were cycling through all 28K features in table 2 for each feature in table 1. And it wasn't finding the correct output, since you were comparing the first record in Table 2 to your feature, instead of the looped feature in table 2 ("feat.FACILITYID" instead of "f.FACILITYID").

Give this a try. It filters table 2 by the FACILITYID of the feature in table 1. If there is a corresponding record in table 2, then it return 1. Otherwise, it returns null (which isn't explicitly needed in this script in my testing)

var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var id = $feature.FACILITYID
var filteredTable = Filter(commericalLine, "FACILITYID = @ID")
if (Count(filteredTable) > 0) return 1;