Hi Field Mappers,
Got an easy win for you.. I think? I am still fairly new to working with FeatureSets in arcade.
I have a parent/child relationship point and record. I want to show the last date checked from the record in the parent pop-up. When I go to add it in as an attribute expression and "Run" it it works, however when I go into map viewer and in Field Maps I can't get it to work.
I've followed a few basic tutorials online, but am not sure what's wrong here.
I have double and triple checked I have the correct FeatureSetByRelationshipName relationship name and checked field names for upper and lower cases.
My parent and child are both points.
var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"BaitStation_Checks"), "DateChecked DES");
var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
relatedinfo = Text((info.DateChecked), "ddd DD/MM/YYYY");
}
DefaultValue(relatedinfo,"No checks to date")
Any help you can offer would be greatly appreciated.
In addition I would like to grab info from two more fields in the most recent check. Same feature we're calling from above. If anyone has a tip for that I'd love to know. Thanks in advance for your time and helping me broaden my arcade knowledge.
Solved! Go to Solution.
Yeah okay, so if you're using the Arcade Element in the popup, the return must be enclosed in those curly brackets. Essentially what you could have done to make your original code work here (as opposed to an attribute expression) is to do this:
return{
type:'text'
text: DefaultValue(relatedinfo, "No checks to date")
}
Try using "DESC" instead of "DES"? I don't know if that's what's going wrong, but I think Arcade using DESC from sorting.
Evidently "DES" is totally fine with Arcade!
It gets weirder and funnier. Literally any text after the field name besides "ASC" is treated as "DESC". A typo on "DESC" is fine. But a typo on "ASC" will give you the opposite!
That is crazy and funny, but I guess that's a built in null check, which has probably helped a lot of people out!
Honestly, I don't see anything wrong with your expression here, except maybe your OrderBy function needs a "C" on "DES"? Attribute rules are supposed to have access to all FeatureSet functions. You're saying that the expression doesn't work in the web map or Field Maps, just in the expression builder?
Two suggestions:
First, include more parameters on your FeatureSetByRelationshipName function. By specifying the fields you want and not including any geometry, less data will be going back and forth, which would speed up a slow expression.
Second, maybe just try some debugging. Add Console statements to your expression, then open your browser's Developer Tools and watch the "Console" tab and see what it says.
var relatedrecords = OrderBy(
FeatureSetByRelationshipName(
$feature,
"BaitStation_Checks",
['DateChecked'],
false
),
"DateChecked DESC"
);
var cnt = Count(relatedrecords);
Console('related record count', cnt);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
Console(info)
relatedinfo = Text((info.DateChecked), "ddd DD/MM/YYYY");
}
return DefaultValue(relatedinfo, "No checks to date")
Another thought is that there have been a lot of reports of FeaturesetByRelationshipName giving people trouble. You could try FeaturesetByName instead?
Interesting not that FeaturesetByRelationshipName actually fixed a problem I had gotten when I was using FeaturesetByName, but hey, might be worth a short either way.
@ZachBodenner @jcarlson Thank you both for your replies!!!
I've learned a lot and feel like I'm armed well for future featureset arcade troubleshooting, and you've really challenged me to up my developer game 🤣 I had a long message written out to you, and then decided to test just one more thing, and well... that thing worked.
Short story
It works if I add it as an Attribute expression not as an Arcade element... maybe that was just a rookie mistake on my part. Why is that?
Long story
It is returning the latest bait station check date in the expression builder. Before it used to only return "No checks to date."
It doesn't show in the pop-up still though, and I've made sure I'm testing on a pop-up that has a bait station check.
I've had a look at the Developer Tools> Console. (Still new to this part, so tell me if I've missed something.)
It looks like it sees there are related records, and the dates for them.
This is my latest arcade expression.
//FeatureSetById(featureSetCollection_, id_)
var relatedrecords = OrderBy(
FeatureSetById(
$map,
"19188cd37b9-layer-124",
['DateChecked'],
false
),
"DateChecked DESC"
);
var cnt = Count(relatedrecords);
Console('related record count', cnt);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
Console(info)
relatedinfo = Text((info.DateChecked), "ddd DD/MM/YYYY");
}
return DefaultValue(relatedinfo, "No checks to date")
It still doesn't show in the pop-up though.
Next steps
Now I'm trying to get the featureset to pull three more fields and output that as "(BaitType) (BaitAdded) by (X) on ddd DD/MM/YYYY."
When you made the arcade element expression, did you remove the pre-filled return portion? The return needs to be in that format for the arcade element version to work, you can't just have a simple return.
Yes I removed this:
Yeah okay, so if you're using the Arcade Element in the popup, the return must be enclosed in those curly brackets. Essentially what you could have done to make your original code work here (as opposed to an attribute expression) is to do this:
return{
type:'text'
text: DefaultValue(relatedinfo, "No checks to date")
}