To post code:
Can't see anything obviously wrong at first glance. Maybe you see features that do have related records, but those records have null values in the date field? In that case, the expression returns an empty string.
Try to incorporate that condition:
var relRec = OrderBy(FeatureSetByRelationshipName($feature , "T4C_Records"), "CollectDate DES")
var info = First(relRec)
return IIf(info == null || info.CollectDate == null,
"None To Date",
Text(ToLocal(info.CollectDate), "MM/DD/Y")
)
Hi Johannes, thanks for the reply!
I tried your example and it returned a date when they exist, however it still did not return "None To Date" for null values. Basically, this returns just the date... I tried using the else to return the null statement without success. Not sure how to expand this expression to do that...
var recOrder = OrderBy(FeatureSetByRelationshipName($feature, "T4C_Records"),"CollectDate DES" );
var countRec = count(recOrder);
var relatedInfo = "";
if (countRec>0) { var info = First(recorder);
relatedInfo = Text(ToLocal(info.CollectDate), "MM/DD/Y");}
return relatedInfo
I got the expression from here Pulling Related Records with Arcade but it did not expand beyond the date pull.
Thanks!
Maybe if you set the return value to the default and only edit it if all the conditions are met?
var recOrder = OrderBy(FeatureSetByRelationshipName($feature, "T4C_Records"),"CollectDate DES" );
var countRec = count(recOrder);
var relatedInfo = "None to date";
if (countRec > 0) {
var lastDate = First(recOrder).CollectDate;
if(lastDate != null) {
relatedInfo = Text(ToLocal(lastDate), "MM/DD/Y");
}
}
return relatedInfo
You could also filter out null dates:
var rec = FeatureSetByRelationshipName($feature, "T4C_Records")
var recFilter = Filter(rec, "CollectDate IS NOT NULL")
var recOrder = OrderBy(recFilter, "CollectDate DES");
var countRec = count(recOrder);
var relatedInfo = "None to date";
if (countRec>0) {
var info = First(recOrder);
relatedInfo = Text(ToLocal(info.CollectDate), "MM/DD/Y");
}
return relatedInfo
Still not working, those both do the same thing as the previous versions... seems like it should be fairly cut and dry but I'm scratching my head for sure