How to get attribute with last date modified from related table using Arcade

40981
39
11-06-2019 02:38 PM
KellyDoss1
Emerging Contributor

Hello all,

 

I'm pretty new to Arcade and I'm having problems.  I believe I need to be using FeatureSets in Arcade.

 

I have a hosted feature layer with several related tables, some of which are 1:M.  In the CIP_Test pop-up, for the 1:M related tables, I only need to show the data from the rows with the latest "Date Modified".

 

I've attached a screenshot of the related table.  Where there are duplicate AcctNo, I only want to show the ProjectPhase (and maybe other fields) for the record that was last modified.

 

Any suggestions on how to do this are much appreciated!  I have gotten nothing but errors in everything I've tried from any forum posts I've found....

0 Kudos
39 Replies
by Anonymous User
Not applicable

I will try the code above to see if it works!  Although I did find out that there is a bug associated with the "FeatureSetByName" function and esri plans on fixing it in the next field maps update!  

0 Kudos
JuliaHillin
New Contributor

Hi @XanderBakker ! I'm late to the party, but I was hoping you still might be able to help me. I've tried implementing the code you provided earlier in this thread and have been unsuccessful. I don't receive any errors, but its also not providing the date of any recent inspections and only printing my else statement. We don't have many records in our related table, so I'm not sure if that might be the issue? I've been struggling with this for several hours and was hoping you might have a solution! Here is a copy of my code:

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"Battery_Inspections"), "inspectiondate DESC");
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
    var info = First(relatedrecords);
    relatedinfo = Text(ToLocal(info.inspectiondate), "M/D/Y, hh:mm");
} else {
    relatedinfo = "No inspections available."
}

return relatedinfo
0 Kudos
AndrewSmith21
Emerging Contributor

Does this code work in 10.6.1 Enterprise?

0 Kudos
Terry_Bearb
Frequent Contributor

@AndrewSmith21 did you ever get a response to this? We are running 11.5 Enterprise and are looking to do this within the map viewer in our portal but we are running into a snag at the moment where it seems as if it is not recognizing our relationship name that lives in our SDE.

Any thoughts @XanderBakker ?

Running this simple arcade gives us this error: Execution error - Line : 2, 10: Invalid parameter

var relatedrecords = FeatureSetByRelationshipName($feature, "DBO.WaterMeter_Backflow_Details");
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
    var info = First(relatedrecords);
    relatedinfo = info.Manufacturer;
}

return relatedinfo

 

0 Kudos
Terry_Bearb
Frequent Contributor

Disregard..I have figured it out. I was typing in the relationship name that resides in our SDE but really it needed to be "DBO.Backflow_Details" which is the name of the related table.

0 Kudos
ClintonKeating
New Contributor

This was very useful. I am trying to use this on an attribute rule for assigning the latest inspection date from related inspection table to the equipment parent. It is working well but the triggers are only on the equipment record so when a new inspection is added the parent equipment record doesn't recognize an insert or update on the parent equipment record. This is on a FGDB to be Published to an Enterprise feature service on portal.  

 

Any thoughts / ideas on this? 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Tim Flynn ,

Remember to return the relatedinfo and not the relatedrecords, but the key to get the most recent date. This is done with the OrderBy, but on the first line the way to order the data was missing. Have a look at the end of the first line of the expression below:

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"AST_Inspection"), "insp_date DESC");
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
 var info = First(relatedrecords);
 relatedinfo = Text(ToLocal(info.insp_date), "MM/DD/Y");
}

return relatedinfo;
TimFlynn
Regular Contributor

So is there a difference between adding in DES vs DESC?  Both seemed to work, at least while I have very few records in the data set.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Timothy.Flynn_ocfl , 

As far as I know they are both valid options... 

kmsmikrud
Frequent Contributor

Hi Xander Bakker and Kelly Doss,

I really appreciate the code for displaying related records in the pop-up using the FeatureSetByRelationshipName. I have a question, I have a point layer with a related table and then a second related table to the first related table. This is from a Survey123 app in which points have related surveys and within the Survey123 there is a few repeat questions hence the second related table. Is it possible to access the second related table thru the pop-up with arcade and what function would you recommend? I would like to summarize counts in the second table displayed by most recent survey date.

thanks in advance!

Kathy

0 Kudos