Issue: Im attempting to pull attributes from a related table into the parent feature class once a particular status has been chosen.
Details: Once a user selects the adoption status as "Approved", I need to retrieve the adopters name, email and phone number from the latest related record. (TEST DATA INCLUDED AS ATTACHMENT)
Current Code:
Solved! Go to Solution.
Just add and OrderBy date to your featureset and call First on it.
Also, do not assign this rule to a field, the return is better like this
https://developers.arcgis.com/arcade/function-reference/featureset_functions/#orderby
if ($feature.Adoption_Status != "Approved") {
return ;
}
var parent_id = $feature.GlobalID;
if (IsEmpty(parent_id)){
return;
}
// Could use https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featuresetbyrelationshipname also
var relatedTab = FeatureSetByName($datastore, "AAS_Adopters", ['GlobalID', 'Parent_GUID', 'Name', 'Email', 'Phone_Number'], false)
var relatedRec = First(OrderBy(Filter(relatedTab, 'Parent_GUID = @parent_id'),'<YOUR DATE FIELD> DESC'))
if (IsEmpty(relatedRec)){
return;
}
return {
"result": {
"attributes": {
"Adopted_By": relatedRec.Name,
"Adopter_Contact_Email": relatedRec.Email,
"Adopter_Contact_Number": relatedRec.Phone_Number
}
}
}
also, please post code as code snippet(javascript for arcade). It really helps.
Just add and OrderBy date to your featureset and call First on it.
Also, do not assign this rule to a field, the return is better like this
https://developers.arcgis.com/arcade/function-reference/featureset_functions/#orderby
if ($feature.Adoption_Status != "Approved") {
return ;
}
var parent_id = $feature.GlobalID;
if (IsEmpty(parent_id)){
return;
}
// Could use https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featuresetbyrelationshipname also
var relatedTab = FeatureSetByName($datastore, "AAS_Adopters", ['GlobalID', 'Parent_GUID', 'Name', 'Email', 'Phone_Number'], false)
var relatedRec = First(OrderBy(Filter(relatedTab, 'Parent_GUID = @parent_id'),'<YOUR DATE FIELD> DESC'))
if (IsEmpty(relatedRec)){
return;
}
return {
"result": {
"attributes": {
"Adopted_By": relatedRec.Name,
"Adopter_Contact_Email": relatedRec.Email,
"Adopter_Contact_Number": relatedRec.Phone_Number
}
}
}
also, please post code as code snippet(javascript for arcade). It really helps.
Thanks a lot for your response Mike. Will try and let you know of the results.