ArcGIS Online DateDiff Arcade Symbology

666
4
Jump to solution
03-26-2021 08:00 AM
Labels (3)
Sietse_de_Haan
New Contributor III

Hi there,

I am very new to coding and using this within my ArcGIS Online maps. I'll first try to explain what I would like to achieve with the expression and than I'll come to what I already have and what I need help with.

So what we have is location of trees with some information within this database. Within this database is also a frequency mentioned for how many times these trees need to be inspected. For example yearly or once every 3 years. For the inpections we use Survey123 form and with a custom URL we copy this frequency (and some more values) within the database of the inspections. This frequency is shown as a number depending on how many years there should be between inspections. So this can be a '1' or a '3' or acualty any number of years.

I would like to use this frequency for my symbology, to change the symbol when the year has passed from 'Inspected' to 'Need to be inspected'

I found this piece of code here and tried to apply this for my case and change the "days" to "years" but it keeps on saying 'Inspected'.. What am I doing wrong?

found:

var days = DateDiff(Now(), $feature.LastSurveyDate, "days");
if (days > 30) {
    return "This has not been surveyed in past 30 days";
} else {
    return "This has been surveyed in past 30 days";
}

 

changed to:

var days = DateDiff(Now(), $feature.test, "year");
if (year > $feature.Frequentie) {
    return "Inspecteren";
} else {
    return "Geïnspecteerd";
}

$feature.Frequentie stands for the amount of years and $feature.test is a date field with testing date for testing the symbology. Normally the $feature.EditDate will be used here. 

 

What I am doing wrong? And what do I have to change to make it work? 

Sietse de Haan
https://www.linkedin.com/in/sietse-h-de-haan/
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor

No, what I meant is that in the second line of your code, you used

 

if (year > $feature.Frequentie) {

 

You didn't declare "year" as a variable, so Arcade is using the built-in value of "year", a function, which will never give you the correct comparison for your field. You declared the variable "days" in your first line to return the difference in years between Now and the date in your test field. That variable is what you should be comparing to Frequentie. You could use this to make it more understandable

var years = DateDiff(Now(), $feature.test, "year");
if (years > $feature.Frequentie) {
    return "Inspecteren";
} else {
    return "Geïnspecteerd";
}

View solution in original post

4 Replies
KenBuja
MVP Honored Contributor

You have "year" in the If statement, which is a reserved word. Did you mean to use the variable "days"?

var days = DateDiff(Now(), $feature.test, "year");
if (days > $feature.Frequentie) {
    return "Inspecteren";
} else {
    return "Geïnspecteerd";
}

 

0 Kudos
Sietse_de_Haan
New Contributor III

Hi @KenBuja

Thanks for your reply. I would love to use the variable 'year' or 'years'(?) Because we inspect the trees basically on a yearly basis. The intervalnof these inspections are 1 or more years. The function DateDiff can use years right? And not only days?

Sietse de Haan
https://www.linkedin.com/in/sietse-h-de-haan/
0 Kudos
KenBuja
MVP Honored Contributor

No, what I meant is that in the second line of your code, you used

 

if (year > $feature.Frequentie) {

 

You didn't declare "year" as a variable, so Arcade is using the built-in value of "year", a function, which will never give you the correct comparison for your field. You declared the variable "days" in your first line to return the difference in years between Now and the date in your test field. That variable is what you should be comparing to Frequentie. You could use this to make it more understandable

var years = DateDiff(Now(), $feature.test, "year");
if (years > $feature.Frequentie) {
    return "Inspecteren";
} else {
    return "Geïnspecteerd";
}
Sietse_de_Haan
New Contributor III

@KenBuja Thank you so much haha. How I didnt see that is beyond me but thank you very much!!

It works now :D 

Sietse de Haan
https://www.linkedin.com/in/sietse-h-de-haan/
0 Kudos