This is my first time writing an Arcade expression and I'm having trouble! I have a feature service of koala sightings that is maintained by volunteers. Once they have completed their data entry they select "YES" from the YES / NO domain assigned to the "Data record complete" (string) field. They then have to enter the current date in the "Date completed" (date) field.
To streamline their data entry, if "Data record complete" = 'YES' I would like to auto-populate "Date completed" with today's date.
In the Field Maps form editor, I have attempted to create a new calculated expression for the "Date completed" field , however it has an error somewhere in the code.:
var recordcomplete = $feature["Data_record_complete"];
var todaydate = Date()
if(recordcomplete = 'YES'){
return todaydate;
}
Solved! Go to Solution.
Your error is in the if statement.
Most programming languages use "=" as assignment (var x = 3) and "==" as check for equal (x == 3 --> true).
if($feature["Data_record_complete"] == "YES") {
return Now()
}
While the default return value of Date() is the current date and time, I would use Now() here. It returns the same value but when reading the code it's clearer what you want to do, as you can construct arbitrary Dates with Date().
Also, depending on your field, you might want to use Today(), which only returns the date without the time.
Your error is in the if statement.
Most programming languages use "=" as assignment (var x = 3) and "==" as check for equal (x == 3 --> true).
if($feature["Data_record_complete"] == "YES") {
return Now()
}
While the default return value of Date() is the current date and time, I would use Now() here. It returns the same value but when reading the code it's clearer what you want to do, as you can construct arbitrary Dates with Date().
Also, depending on your field, you might want to use Today(), which only returns the date without the time.
Gosh, that was simple solution thank you!