Displaying proper symbology with Arcade in ArcPro/AGOL

845
5
Jump to solution
04-24-2019 09:59 AM
Ipad1Avion
New Contributor II

I'm having issues across platforms using Arcade to break my Valves features into different classes. The following script works perfectly in ArcPro (31,536,000,000 is the rough number of milliseconds in a year, and the code will properly change colors of valves outside of one year of maintenance within a few minutes):

arcade code breaking features up from current to previous dates of operation

That code yields the following result in ArcPro (Note the broken valve is just showing it works in Pro, broken and lost symbology works in AGOL as well, but the data has not been updated to reflect the change in Pro):

Features classified by broken, lost, and dates

The result in an AGOL web app follows; code seems to only segregate elapsed time based on current date, not <null> values. Again, it also works for broken/lost valves. All of the symbology displays in the legend, however.

 

I've tested the code using Collector and Explorer using both iPad and Android mobile platforms, but I don't get anything other than default value symbol. The web app still displays the same symbology from a mobile platform as it does PC, however, I don't collect points from our web app. We use an Arrow GPS connected to an iPad as our collection platform, and it doesn't make sense to switch apps to update.

Default symbology displayed on Android, though the separate classes still exist in the legend:

Any recommendations or help is appreciated.  I've pasted the code on the bottom for easy manipulation. I'm just getting into code, and don't have the knowledge yet to make a more advanced app that can collect that we can download. Thanks in advance, and I hope this helps you all out there looking for a similar solution to finding a longer time based method for annual maintenance. 

collector arcade arcade expression arcade symbology arcade attribute expressions #arcade arcpro #AGOL long time #time #year #annual #annualmaintenance

// set parameters for finding broken or lost valves first.

var class

If ($feature.BROKEN == "YES") {
class = "Broken";
} else if ($feature.FOUND == "LOST") {
class = "Lost";
} else {

// this classification sets up different classes based on time of maintenance. Symbology adjustable via regular methods

var startDate = Date($feature.DATE_OPERATION_CURRENT);
var endDate = Date(Today ());
var change = DateDiff(endDate, startDate, 'value');

var result = When (change > 31536000000, "Due", change <= 31536000000, "Current", "Data Not Current")

return result

}

return class

//I realize I could probably replace "var result" with "class"

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

As far as I understand symbology based on Arcade is not yet supported in Collector. 

Some small changes to the Arcade expression (although this will not solve anything):

// set parameters for finding broken or lost valves first.
var class = "";
if ($feature.BROKEN == "YES") {
class = "Broken";
} else if ($feature.FOUND == "LOST") {
class = "Lost";
} else {
// this classification sets up different classes based on time of maintenance. Symbology adjustable via regular methods
var startDate = $feature.DATE_OPERATION_CURRENT;
var endDate = Today();
var change = DateDiff(endDate, startDate, 'years');
var class = When(change > 1.0, "Due", change <= 1.0, "Current", "Data Not Current");
}
return class;

View solution in original post

5 Replies
XanderBakker
Esri Esteemed Contributor

As far as I understand symbology based on Arcade is not yet supported in Collector. 

Some small changes to the Arcade expression (although this will not solve anything):

// set parameters for finding broken or lost valves first.
var class = "";
if ($feature.BROKEN == "YES") {
class = "Broken";
} else if ($feature.FOUND == "LOST") {
class = "Lost";
} else {
// this classification sets up different classes based on time of maintenance. Symbology adjustable via regular methods
var startDate = $feature.DATE_OPERATION_CURRENT;
var endDate = Today();
var change = DateDiff(endDate, startDate, 'years');
var class = When(change > 1.0, "Due", change <= 1.0, "Current", "Data Not Current");
}
return class;

View solution in original post

Ipad1Avion
New Contributor II

I initially tried years, but from my testing, it only seemed to strip years from the date and subtract, even with the ".0" added. December 2018 to January 2019 would result in one full year, and the maintenance schedule thrown off (2019.0-2018.0 still 1.0). It is useful for multiple years though. As I've seen from some of your previous responses on the forums, months are only assigned 0-11 and days don't extend beyond 31, so after a couple days and some Googling I found the 'value' data format in milliseconds to work, plus you can code in conversions for days, minutes, hours or years in your fields as needed. 

Thanks for the input! I hoped Arcade not being in Collector yet was the issue. They are planning on adding the functionality though, right? 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Absolutely, Collector will have support for Arcade in the future.

I just did a small test with the DateDiff and year option and it does not strip the decimals:

var startDate = Date(2018,3,24)
var endDate = Today();
var change = DateDiff(endDate, startDate, 'years');
return change; // 1.0026881720430108

var startDate = Date(2018,3,26)
var endDate = Today();
var change = DateDiff(endDate, startDate, 'years');
return change; // 0.9972222222222222
0 Kudos
Ipad1Avion
New Contributor II

Interesting. I'll give it a test in Pro, and report back. I know I tried DateDiff in 'years' early on, using change values of 1.0, without success.

0 Kudos
Ipad1Avion
New Contributor II

That did work, maybe not the minutes difference milliseconds provides, but next day is good enough. Would adding more zeros after the decimal yield more precise results? I'm looking through past samples to see where I went wrong. Thanks!

0 Kudos