I successfully used https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2018/12/10/overlapping-features-i... in two separate scripts to combine two surveys with the same feature layer points. I am getting the results I desire separately. So now I want to add a third piece and that is a conditional - IF A doesn't exist then return B else return A.
However I have some code and it is trying to return the entire feature class and I can't seem to pull just one field from the feature class. (see Script 3) NOTE: I am relatively new to Arcade so I may be going about this all wrong.
Here are the two scripts that are pulling the info I want:
Script 1: var intersectLayer =Intersects(FeatureSetByName($map,"BowersTransactions"), $feature)
for (var f in intersectLayer){
return f.feno2
}
Script 2: var intersectLayer =Intersects(FeatureSetByName($map,"BowersInspections"), $feature)
for (var f in intersectLayer){
return f.extinguisherno
}
Script 3: var inspfe =Intersects(FeatureSetByName($map,"BowersInspections"), $feature)
var transfe =Intersects(FeatureSetByName($map,"BowersTransactions"), $feature)
if (isEmpty(transfe))
{return inspfe;}
else {return transfe;}
Script 3 doesn't error out it tries to display all 20 or so fields. So it won't allow me to add it to a popup since it is too much information. I included the result from Script 3.
I thought briefly that FeatureSetByID might narrow this down to one field which is what i want however the little bit of reading I have done on that function seems to indicate that it uses arrays and I am just trying to pull the data from a field if it exists.
Hi Adam Levine ,
A couple of comments and questions as to what you are doing:
See below an example of what you can do, just returning one field based on what you described:
var result = "";
var transfe =Intersects(FeatureSetByName($map,"BowersTransactions"), $feature);
if (Count(transfe)==0) {
// no BowersTransactions
var inspfe =Intersects(FeatureSetByName($map,"BowersInspections"), $feature);
if (Count(inspfe)==0){
// BowersInspections either
result = "No results found";
} else {
// just BowersInspections
result = First(inspfe).extinguisherno;
}
} else {
// BowersTransactions found, don't check BowersInspections
result = First(transfe).feno2;
}
return result;
Xander,
Thanks for your help....I tested this with a technician and it is close to what we are looking for but now I think we have to adjust for the latest transaction (based on a date field). So I will have to look at this document How to get attribute with last date modified from related table using Arcade perhaps as a guide?
Probably not this simple however can I create another variable (using some of the above code) that would be based on the Count being greater than 0?
Adam
Hi adaml ,
The link you mentioned is a good start to get the most recent record from a related table. You mention that your requirement is more complex. If you can share more details, maybe I can give some more tips on how to do that.
Xander,
Let me clarify - I need the last transaction extinguisher number instead of the intersect (it seems to be pulling up the first one) that is really the only change to what I am trying to do. If there isn't a transaction extinguisher number it should defer to the inspection extinguisher number. So, it is close to what I need.
I believe the article i posted wouldn't be applicable because I am not using a related table. Correct?
Adam
Hi Adam Levine ,
Thanks for the clarification, although I still have a couple of questions. But first a note on the expression from the link you shared:
var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature, "RelData"), "DateModified DES");
var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
relatedinfo = info.ProjectPhase + " (" + Text(ToLocal(info.DateModified), "MM/DD/Y") + ")";
}
return relatedinfo;
Notice that on line 1 the data is sorted with the "OrderBy". As parameter "DateModified DES" is provided so it will order de records on the field DateModified in descending order. When you take the "First" (see line 6) it will take the most recent record according to the information stored in DateModified.
In case there are no related records you could include an else statement on line 8.
You mention that you are not using a related table. Do you have multi temporal data in the transaction table? If so, you should probably filter the layer first before sorting the data. Could you show the attribute table to see how it is structured?
Xander,
I did a quick data export to Excel from the Survey123 Transaction Survey - so I have provided a screenshot of the fields and highlighted the date fields that I could use. I have also already filtered the transactions on 2020 - these are annual inspections however if there is any human error and they have to submit multiple transactions I would like the last extinguisher number to be used in the pop up based on the latest date. Hope that clarifies everything.
Hi adaml ,
I' afraid that the export to Excel does not take all my doubts away. Do you have any repeats in you survey? Also the image shows the aliases created in the hosted featurelayer and the actual field names might be different. Is it possible to provide a screenshot of the attribute table of the hosted featurelayer with data in it?
Xander,
It is tough to get a screenshot with the data only because there are so many fields - I have Notes being pulled into the Survey. I have included a screenshot with the actual field names. I also included a screenshot with the data containing the one date field that I created for this survey.
Thanks,
Adam
Hi Adam Levine ,
Thanks for sharing. So your date field is called "adjdate", but what identifies the group of data you want to extract the latest from. Is that the Location ID (but in your screenshot that field appears to be empty)? I am assuming you have one layer and for a certain attribute of a feature you want to access the layer and all features that share that value and determine the latest date in the adjdate field and when found show a certain attribute. Is this the case. Sorry for all these questions, but based on two records it's kinda hard to know.