0

What I have:

  • A hosted joined view layer with a Inspection Date field ('insdate') and an Operable field ('h_operable'). The view is defined such that it only holds the most recent record for each asset. I.e. Assetid 1 will have a single Inspection Date and operable value. The table currently has several records with inspection dates shown below:

enter image description here

What I am trying to accomplish:

  • If Inspection date is less than 1 year old and Operable is equal to 1 then symbology class would be "Operable".
  • If Inspection date is less than 1 year old and Operable is equal to 2 then symbology class would be "Inoperable"
  • If inspection date is more than 1 year old then symbology class would be null or other and not displayed.

What I have tried: The following code is what I have attempted to use in the Style Options expression in MapViewer

var now = Date();
var inspection = $feature["insdate_1682094024219"];
var age = DateDiff(inspection, now);
var op =$feature["h_operable"];
var opcondition = age < 365 && op == 1;
var inopcondition =  age < 365 && op == 0;
var nodraw = age > 365
When(opcondition, "Operable", inopcondition, "Inoperable", nodraw, "Other", "Inconclusive");

Issue:

  • Whenever I apply, the op == x value is honored, and drawn as defined in var opcondition or var inopcondition. However, the date parameter is NOT honored, and records that are more than 365 days old still draw as "Operable" or "Inoperable" instead of "Other". This is pictured below, where the date is more than 1 year old, and still being drawn on the map.

enter image description here

2 Answers 2

0

Would it be possible to split this between a filter for the date, and a separate expression for the Operable function?

The only reason I bring this up is, it sounds like you are trying to filter out everything more than a year old anyway. Map viewer filters for this have worked for me, and then all you're adding is the operability expression by itself.

3
  • It looks like this will be the route I end up taking on this project. I will update once I am able to get back around and attempt to implement this. Jun 19, 2023 at 19:27
  • This worked beautifully. Honestly, I am not sure how I was overlooking filters when I was writing this question. Thank you! Jun 28, 2023 at 18:34
  • You're kindly welcome!
    – Alex Page
    Jun 29, 2023 at 19:37
0

To comment on why the Arcade script might not have had the results you expected:

So when you ran the script age was likely a large negative number representing the milliseconds difference between the two datetimes. This modified script may be closer to your initial description.

var now = Date();
var inspection = $feature["insdate_1682094024219"];
var age = DateDiff(now, inspection, 'years');
var op = $feature["h_operable"];
var opcondition = age < 1 && op == 1;
var inopcondition =  age < 1 && op == 0;
var nodraw = age > 1
When(opcondition, "Operable", inopcondition, "Inoperable", nodraw, "Other", "Inconclusive");

Filters are likely to be more performant that the corresponding Arcade script.

1
  • 1
    Thanks for the input! My arcade is still very beginner level. Alex Page above you definitely had the simpler solution. I'm not sure why I was completely looking over filters when I wrote this question. Jun 28, 2023 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.