Arcade - Declare variable at given time

663
5
06-28-2019 09:59 AM
AlexMetzler
New Contributor III

Using Arcade, I am trying to declare a variable at 6pm every day. I want to record the temperature (from field $feature.TEMP) at 6pm each day and have that stored as a variable until the next day at 6pm. Here is what I have tried:

var TimeNow = Hour(Now()) + (Minute(Now())/100)
var Temp = 100

if (TimeNow == 18.00){
var Temp = $feature.TEMP;
}
else {
var Temp = Temp;
}
return Temp

However, using IF or WHEN only populates the temperature for that minute when the statements are true. Is there a function I could write to declare the variable at 6pm?

0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

Hi Alex Metzler ,

Can you explain a little more where you want to apply this Arcade expression and why? The where will explain more about when it will be executed. You also mention that you want to store this as a variable. Can you explain a little more about how and where you will store this variable and what you are thinking of doing with it later on?

0 Kudos
AlexMetzler
New Contributor III

Can you explain a little more where you want to apply this Arcade expression and why? This expression is in the symbology of a point layer. The layer has a temperature field that is constantly updated, the temperature is the current temperature, there is only one record.

Can you explain a little more about how and where you will store this variable and what you are thinking of doing with it later on? I need it to take a snapshot of the temperature at 6pm and keep it (presumably stored as a variable to return and indicate the symbology for 6pm). I want the color of the point to symbolize what the temperature was at 6pm.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Alex Metzler ,

Thanks for the additional explanation, but I think there will be a challenge in trying to accomplish this.

This expression is in the symbology of a point layer. The layer has a temperature field that is constantly updated, the temperature is the current temperature, there is only one record. I need it to take a snapshot of the temperature at 6pm and keep it (presumably stored as a variable to return and indicate the symbology for 6pm). I want the color of the point to symbolize what the temperature was at 6pm.

So, the Arcade expression is applied every time it needs to draw a feature. Since the expression does not write the value to the feature attribute, at a different time than 6 pm there will not be another value that can be drawn (the value "100" in your expression would be visualized at all other times). I think the only option would be to use Arcade expression in an attribute rule or use a schedule task Python script that updates a field at 6 pm with the current value.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi ametzler_mprb 

About the schedules task that would be required for your case, I just saw that in the Road map of ArcGIS Pro: https://community.esri.com/docs/DOC-13641-arcgis-pro-roadmap-july-2019 they are mentioning a new feature:

Geoprocessing Scheduler - Choose to run your tool immediately, or select a date and time in the future to run it, as well as recurrence.

... this could be interesting for your use case.

0 Kudos
AlexMetzler
New Contributor III

Thanks Xander. That may be it. I could run the tool and write the value at 6pm to the original data table.