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

24294
37
11-06-2019 02:38 PM
KellyDoss1
New Contributor II

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
37 Replies
kmsmikrud
Occasional Contributor III

Hi Xander Bakker‌,

THANK-YOU SO MUCH! The latter code is exactly what I was hoping to do but unable to put the code together in how to access the counts in the second related table. In regards to accessing all previous survey counts at this time the goal was just to access the last survey count which is what you provided. I can't tell you how much I appreciate your help on this and its very exciting to see the results show up.

I am curious if the arcade will work offline in the Collector for ArcGIS app with iOS device which is really the goal for surveyors to be able to view previous survey counts when they are out. If this functionality isn't available now hopefully it is on the road map.

Again thank-you so much for your time in looking at the data and sharing the code!

Kathy

XanderBakker
Esri Esteemed Contributor

Hi kmsmikrud ,

I am glad that the expression is doing what you wanted to achieve. At this point I am not sure if the expression will work in Collector. Support for Arcade is incrementing with each release, but the best you can do is try it out and when you do, please post back your findings.

0 Kudos
IvanKuzmic
New Contributor

Hello @XanderBakker ,

This post helped me a lot as I am beginner to the world of Arcade so thanks so much.

I have one question, is there a way to make some loop that can go thro multiple related record and show them as one attribute (or more) in pop up.

This is how it looks now, only showing one related record:

IvanKuzmic_0-1608296203894.png

And code used was yours with some simple modifications:

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"ActivitesMaster"), "Activity DESC");
var cnt = Count(relatedrecords);

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

return relatedinfo;

Is something similar to For or While Loop available in Arcade? Main problem is that some features have 1 related attribute, and up to 3 or 4 in some different cases. This would help me and the several apps that I am developing. 

Thanks in advance,

Ivan 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @IvanKuzmic ,

 

Sorry for the delay in my reply. I was (and still am on vacation).

You could try something like this:

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"ActivitesMaster"), "Activity DESC");
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
    for (var relatedrecord in relatedrecords) {
        if (relatedinfo == "") {
            relatedinfo = relatedrecord.Activity;
        } else {
            relatedinfo += TextFormatting.NewLine + relatedrecord.Activity;
        }
    }
}

return relatedinfo;
IvanKuzmic
New Contributor

@XanderBakker Thanks for this, sorry that you are working from vacation.

This is now working and showing activity as it was supposed to!

Thanks again and continue great work!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @IvanKuzmic , glad to hear this!

0 Kudos
RyanMiller6
New Contributor II

Hi Xander-

Any idea why the Related Records would not be available under Globals > $feature ?  I would like to use the FeatureSetByRelationshipName but I cannot without that.  What is the typical cause of this?  Thank you in advance!

expression.PNG

0 Kudos
Amarz
by
Occasional Contributor II

I see this when I am accessing the data from the datastore. However, when I publish the data from ArcPro with the Layer and its respective related table, I am then able to see the Related Records item under $feature.

0 Kudos