Arcade Expressions Populating Dates

1304
8
02-08-2021 10:09 AM
Labels (2)
Larkin
by
New Contributor

Hi, I am trying to create a pop-up field that will expedite the work flow of some things we are trying. I have an idea what I am trying to do but I am not sure if this is possible with Arcade.

Essentially we have a Layer that people will change based on status of an object. What I want is when that layer is changed to update another field of that object with the current date (Thinking Arcade Pop-Up Expression).

The issue I have run into is that once the date changes it changes to the current day or the layer is changed to something else, the Date gets removed.

My solution was for the Arcade Expression to do an IIF check to see if there is already a value and if so to keep it, otherwise it would update. My problem with this is I can't seem to find anyway for the IIF Statement to check the current value of the Expression. 

Is what I am asking beyond the scope of AGOL and Arcade?

0 Kudos
8 Replies
DavidPike
MVP Frequent Contributor

I'm not completely sure of what you're envisaging, but can you just assess if there's a value in the field with isEmpty() and an IF ELSE block?

I've done a terrible sample in the Aracde playground with some dummy datastore data.

if (IsEmpty(FeatureSetByName($datastore,"Building_Footprints.LASTUPDATE"))){
    return Now()}
else{
    return (FeatureSetByName($datastore,"Building_Footprints.LASTUPDATE"))
}
0 Kudos
Larkin
by
New Contributor

Thanks for the reply.  

Basically, if there is a line - someone flips the line layer from "Waiting" to "Start" when that layer gets changed the first (and only the first time) I want it to update a date field "Start Date" with the date it was changed. Then when someone flips from "Start" to "Finish" a Date field for "Finish Date" gets updated.

The issue I was running into with an IF and even tried a WHEN, was that the fields would update the next day with the current date (So if it was updated today Feb 8, tomorrow it would say Feb 9) or if the layer was changed it would remove the date.

I will look into this Datastore and see if it works for us.

0 Kudos
DavidPike
MVP Frequent Contributor

Oh I guess that should be easy enough,

just an IF

where Field 1 = 'Start' AND IsEmpty is TRUE -> populate with time Now()

ELSE return current/old value.

Then the similar concept for finish date.

The Datastore is irrelevant, its just useful to use to trial in the Arcade Playground.

0 Kudos
Larkin
by
New Contributor

Yeah, that is the part where I am stuck. How do I return the current value of an Arcade Expression Popup?

0 Kudos
DavidPike
MVP Frequent Contributor

So for example - for each iterated row - $feature["STATUS"] would be the current value in a field called 'STATUS' which could be Blank, 'WAITING', 'STARTED' or 'FINISHED'.

$feature["STARTTIME"] would have a expression whereby if = 'STARTED' AND isEmpty = TRUE, return the current time.

if = 'STARTED' and isEmpty is FALSE, just return the original value.  This can probably just be done in the ELSE block of the statement:

NB I can't write Javascript properly

 

var startTime = 'yesterday'
var status = 'Started'

if (IsEmpty(startTime) && status == 'Started'){
    return Now()}
else{
    return startTime
}

 

try the above out in that Arcade playground ArcGIS Arcade | ArcGIS for Developers, change the starttime value to '' and see how it changes.

You'd apply similar logic to the FINISHTIME

0 Kudos
Larkin
by
New Contributor

This definitely got me going in the right direction, but I think there may be an issue with just what I want done and how AGOL works. 

I guess I should've pointed out I want the date to stay after changing the layer.

I noticed with having the variables declared as "" at the start it would reset them each time the line layer changed so that didn't help. But even removing the declarations I don't think AGOL remembers the variables? Because each time I would change the layer it would break the date again. 

 

In this example SPS = Start

 

var startTime
var status 

if(find("SPS",$feature.LAYER,0) > 0){
    status = "SPS"
}

if (IsEmpty(startTime) && status == "SPS"){
    startTime = now()
    return startTime}
else{
    return startTime
}

 

0 Kudos
DavidPike
MVP Frequent Contributor

Those variables were declared just for the example to work in the playground.  In your code they should represent the actual fields $feature["STARTTIME"] and $feature["STATUS"]. Otherwise you're just assessing NULL variables.

var startTime = $feature["STARTTIME"]

var status = $feature["STATUS"]

I'm also thinking that the time of the field population will be dependant on the refresh interval of the layer, but I'm not sure, and maybe an edit refreshes the layer also. 

An attribute rule might be better (never used one) but I don't think AGOL supports them at the moment.

0 Kudos
Larkin
by
New Contributor

Okay I understand, now the hurdle again is somehow updating those fields. As you can see with the code below I can read from the Start Date field (SPS_Date) which would be a blank BUT I am not sure if AGOL has a way to write to that field? so it would always be blank.... I tried a few things like $feature["SPS_Date"] = now() but it didn't like that.

var startTime = $feature["SPS_Date"]
var status = $feature.LAYER

if (IsEmpty(startTime) && status == "02. SPS"){
    return now()}
else{
    return startTime
}

 

0 Kudos