Arcade date return error

1645
6
Jump to solution
05-06-2022 06:57 AM
ScottStepro1
New Contributor III

Good morning, 

New to Arcade and was able to borrow and modify this statement from others to pull last date returns from related tables.

Background: This is used to pull last dates from two different tables and display them in the a popup, one table is for collections, the other is for assessments.  This data is used in field to record garbage collection activities and assess overall cleanliness of a stretch of road.

What it does: The script looks at the table, find the last record date of a selected segment and if none found, return the text "none to date".

Issue: As you can see from the screen shots attached, It works like a champ for the collections table but not for the assessment table and not sure why. (tables and images attached for reference)

Only noticeable difference in the tables (to me): The collection table has finish and start date fields and attachments enabled whereas the collection table only has a single date field and no attachments.  Layer and tables were created, related and shared to AGOL via ArcMAP.  

COLLECTION

var relRec = orderby(FeatureSetByRelationshipName($feature,"Collections"), "FinishTime DES");
var cnt = Count(relRec);
var relatedInfo = "";
if (cnt>0) { var info = First(relRec);
relatedInfo = Text(ToLocal(info.FinishTime),"MM/DD/Y");
} else var relatedInfo="None To Date";

return relatedInfo;

ASSESSMENT

var relRec = orderby(FeatureSetByRelationshipName($feature,"Assessments"), "AssessDate DES");
var cnt = Count(relRec);
var relatedInfo = "";
if (cnt>0) { var info = First(relRec);
relatedInfo = Text(ToLocal(info.FinishTime),"MM/DD/Y");
} else var relatedInfo="None To Date";

return relatedInfo;

Scratching my head...

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ScottStepro1
New Contributor III

Found it! See bold...

var relRec = orderby(FeatureSetByRelationshipName($feature,"Assessments"), "AssessDate DES");
var cnt = Count(relRec);
var relatedInfo = "";
if (cnt>0) { var info = First(relRec);
relatedInfo = Text(ToLocal(info.FinishTime),"MM/DD/Y");
} else var relatedInfo="None To Date";

View solution in original post

6 Replies
jcarlson
MVP Esteemed Contributor

What is the expression for the assessments?

- Josh Carlson
Kendall County GIS
0 Kudos
ScottStepro1
New Contributor III

That would help indeed... 

UPDATED ABOVE

0 Kudos
ScottStepro1
New Contributor III

Found it! See bold...

var relRec = orderby(FeatureSetByRelationshipName($feature,"Assessments"), "AssessDate DES");
var cnt = Count(relRec);
var relatedInfo = "";
if (cnt>0) { var info = First(relRec);
relatedInfo = Text(ToLocal(info.FinishTime),"MM/DD/Y");
} else var relatedInfo="None To Date";

jcarlson
MVP Esteemed Contributor

Hm. I figured they were probably pretty similar. The only thing I can figure is that there's some error happening earlier in the expression. Since you initially set the relatedInfo variable to an empty string, maybe that's what is being returned?

Try changing that third line to "var relatedInfo = 'test value'" and see if your popup returns that, or if it's truly not returning anything at all.

Another idea is to include some Console commands in your expression to check the output. Maybe include Console(relRec) and Console(cnt) to see if your initial steps are returning what you expect.

- Josh Carlson
Kendall County GIS
0 Kudos
ScottStepro1
New Contributor III

I figured it out... totally overlooked changing the code in the text conversion in line 5 thanks for looking at it Josh 

0 Kudos
jcarlson
MVP Esteemed Contributor

Any time! Sometimes just sharing the problem makes it clearer to you, even if you end up figuring it out for yourself.

- Josh Carlson
Kendall County GIS
0 Kudos