Select to view content in your preferred language

Arcade expression - Related Table

1054
4
01-08-2023 12:53 PM
Labels (1)
crbdata
Emerging Contributor

Hi all! I am somewhat new to using Arcade and need some help to populate a field based on the most recent related record.  

The field I would like to populate is CRNT_DAMAGE from the newest related record "Individual Palm Damage Survey" based on the field "SurveyDate".  The condition I would like met is if "SpearDamage" and "BoreHoles" == No as well as "InnerFrondsDamaged" and "OuterFrondsDamaged" == 0, then the return value would be "No" for CRNT_Damage.  All else would return "Yes".

Please comment bellow if you have suggestions or can refer me to a similar expression.

Thank you all!

 

Untitled4.jpg

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor
// load the related rows, using one of two ways:

// either load the featureset and filter it (replace the key field names)
var related_fs = FeaturesetByPortalItem(...)
var key_value = $feature.PrimaryKey
var related_rows = Filter(related_fs, "ForeignKey = @key_value")

// or load only the related rows, using the name of the relationship class
var related_rows = FeaturesetByRelationshipName($feature, "RelationshipName")

// get the latest survey
var latest_survey = First(OrderBy(related_rows, "SurveyDate DESC"))

// return a default value if no survey was found
if(latest_survey == null) {
    return "not surveyed yet"
}

// if all damage types are non-existent, the palm is undamaged
if(latest_survey.SpearDamage == "No" && latest_survey.BoreHoles == "No" && latest_survey.InnerFrondsDamaged == 0 && latest_survey.OuterFrondsDamaged == 0) {
    return "No"
}

// else it is damaged
return "Yes"

Have a great day!
Johannes
crbdata
Emerging Contributor

Johannes- this is awesome, I'm looking forward to implementing this expression! 

 

Thank you thank you!

 

0 Kudos
CRBData1
New Contributor

Hi Johannes-

Upon testing the arcade expression, this was the error message received. Do you know what the error is for?

"Execution error - Line : 2, 26: Invalid parameter"

Thank you in advance!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Judging from the fields, you are writing this expression in the palm survey table. But it should be written for the palm layer.


Have a great day!
Johannes
0 Kudos