Select to view content in your preferred language

Pull attributes from Related Table into Parent feature class

583
2
Jump to solution
09-16-2024 08:30 AM
JoeRob_AWPM
Emerging Contributor

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:

var parent_id = $feature.GlobalID;
if (IsEmpty(parent_id))
    return parent_id;


var relatedTab = FeatureSetByName($datastore,"AAS_Adopters",['GlobalID','Parent_GUID','Name','Email','Phone_Number'], false)

var relatedRec = Filter(relatedTab, 'Parent_GUID = @parent_id')


if ($feature.Adoption_Status != "Approved") {
return parent_id;
}
return {
"result":{
    "attributes": {
        "Adopted_By": relatedRec.Name,
        "Adopter_Contact_Email":relatedRec.Email,
        "Adopter_Contact_Number":relatedRec.Phone_Number
}
}
}
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor

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.

 

View solution in original post

2 Replies
MikeMillerGIS
Esri Frequent Contributor

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.

 

JoeRob_AWPM
Emerging Contributor

Thanks a lot for your response Mike. Will try and let you know of the results. 

0 Kudos