Select to view content in your preferred language

Problem with Arcade Expression to Symbolize Field Differences

982
4
08-17-2020 02:44 PM
LindsaySpencer
Occasional Contributor

Ok GIS-ers. I am relatively new to Arcade, so please be kind!  I feel like I have been looking at this for way too long, and because of that I have likely been overlooking something incredibly simple...but I just can't figure this out! Help!?!?

Goal: To symbolize field data by whether or not it has been edited. Editor Tracking and Sync are ON

Approach: Use the difference between the $feature.CreationDate (when i published the data) and $feature.EditDate (this will be identical to CreationDate UNLESS the data has been edited) as the key to creating this symbology. I do have several data points that have been edited on different occasions, and therefore their EditDate and CreationDate attributes are different (verified this in table and in Console function).

Expression 1 & 2: Returns everything as 'Not Visited'

if ($feature.Creator != $feature.Editor){
var Status = "Visited"
return Status
}
else {
return "Not Visited"
}

__________________________________________________________________

if (DateDiff($feature.CreationDate,$feature.EditDate,"minutes")<=0){
return "Not Visited";
}
else{
return "Visited";
}

Not Separated

Expression 3 & 4: Only 'Not Visited' features were symbolized, 'Visited' features were clumped into 'Other'

Iif($feature.CreationDate != $feature.EditDate, "Visited", "Not Visited")

___________________________________________________________________

When($feature.CreationDate != $feature.EditDate, "Visited", "Not Visited")

Not Rendered

There are about 4 more ways I went about trying to create these 2 separate symbols based off of the creator and editor dates, but each one of them resulted in 1 of these 2 results. Additionally, I made sure the expression was reading the correct fields and the correct data types, as I printed them to the console and they are exactly as they should be. 

Any help on this would be appreciated! I feel like it should be such a simple solution, but I cannot figure it out!

Thank you!

0 Kudos
4 Replies
XanderBakker
Esri Esteemed Contributor

Hi Lindsay Spencer ,

Actually, I don't see anything wrong with your expressions. I did a test on ArcGIS Online and the results were correct using your expressions.  Since you posted this in the ArcGIS Pro SDK, I assume you are using ArcGIS Pro, so I also did a test to see if anything was different. In this case I used a Utility Network v4 in a FGDB, but the editor tracking fields seem to be named differently ($feature.CREATIONDATE, $feature.CREATOR, $feature.LASTUPDATE and  $feature.UPDATEDBY). However, after changing the names of the fields, your expressions worked just fine on my data. 

It is very strange that in your case when two options are provided ("visited" and "not visited") a third is returned. 

Would it be possible to have access to (a part of) the data?

0 Kudos
LindsaySpencer
Occasional Contributor

Hi Xander Bakker! Thanks so much for the reply.

In answer to your question - I decided to post this in SDK Pro mainly because I published the source data from Pro, however I am trying to change the symbology with Arcade in AGOL - so I probably mis-categorized the problem up front. I'm trying to symbolize using the auto-generated fields from AGOL (when you enable editor tracking these fields are generated), which aren't available until you publish and track online.

And I do not have permissions to share data outside of my Org, but I'm happy share a screenshot of part of the table with you to get things started. And if that's not detailed enough to reproduce the error, I can create some dummy data in the layer, export it as a fgdb and upload it here. However, doing so will overwrite all of the time/date info to the export time/date. Let me know if there is another way for you to try and replicate this issue! Thanks!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Lindsay Spencer ,

So, you have the data in AGOL, but you can't share it outside you organization. I understand, no problem. Since I haven't been able to reproduce the problem in Pro or in AGOL, if you could create a dummy dataset that does not have any sensitive information and share that in a group in AGOL and invite me to that group using my AGOL account "xbakker.spx" I would be able to have a look. That way you will only share a dummy set of data (not publicly, just with the people that have access to the group) and there is no need to export to a FGDB and send that, publish it again, etc.

From the screenshot you posted, I can see that there both visited and not visited cases and applying the expression should have worked. However, it would be good to have access to the dummy data to validate a couple of things.

0 Kudos
KenBuja
MVP Esteemed Contributor

Just a minor change gives me the expected results. The DateDiff here will result in negative numbers as written, so change the evaulator, switch the position of the EditDate and CreationDate, or use the Abs function

if (DateDiff($feature.CreationDate, $feature.EditDate, "minutes") == 0) {
if (DateDiff($feature.EditDate, $feature.CreationDate, "minutes") <= 0) {
if (Abs(DateDiff($feature.CreationDate, $feature.EditDate, "minutes")) <= 0) {
0 Kudos