Select to view content in your preferred language

Getting a Script to Update only when a point is placed, not when it's Edited.

380
2
04-13-2023 01:42 PM
NathanMiller7
New Contributor
I'm the GIS Coordinator for our County and I'm posting this question for one of my users in my organization. They have written a script that works perfectly for their needs, it locates the nearest weather station and collects the data listed on line 4 and auto fills the fields they need filled. The script is below if that will help answer the question we are posing to anyone that can help. They want this data to only populate when the point is placed on the map the first time. Later there are edits that will be done as part of the workflow to those points to update other fields as needed. The problem that comes up is that when those points are edited the data collected from the arcade script updates with the latest information from those weather stations and they need to have that data remain the same from when the point was placed not from when edits were made. Is there a way to make it so that this data only populates when a point is placed on not update when it's edited?
 
//er data from closest NWS station//
var searchdist =35;
var stations = Intersects(FeatureSetByName($map, 'Stations',["STATION_NAME",'DEW_POINT','OBS_DATETIME','R_HUMIDITYTEMP','TEMP','WIND_SPEED']),Buffer($feature,searchdist, "miles"));
var minDistance = 50
var nearStation;

//console(count(stations))
//return stations
for (var station in stations){
    var stationDist = Round(distance(station, $feature, "miles"),3);
    //var key = text(stationDist, "00.00");
    console (stationDist);
    //if statment to find closest station
    if (stationDist < minDistance){
        minDistance = stationDist;
        nearStation = station;
    }
}
return nearStation.station_name
0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

What context is this being used in? Attribute rules can be configured to "fire" on new features only. Or is this for a smart form for Field Maps or the Edit widget in a web tool?

Anyway, a simple method would be to first check if the field is empty first, and to stop executing if a value already exists.

if (IsEmpty($feature['your_field'])) {
// put the rest of the expression in here
} else {
// return the original value otherwise
return $feature['your_field']
}
- Josh Carlson
Kendall County GIS
JoshuaSharp-Heward
Occasional Contributor III

Adding to the above poster's comment, if you're doing this in a smart form/Field Maps, then you can just edit the final line to be this:

 

IIF($editcontext.editType == "INSERT", nearStation.station_name, destinationField)

 

With destinationField being the field you're writing the station name to. Which will mean that if a point is being added for the first time it will do the intersect and populate the field with the closest station, but if it's an update/edit then it just returns the current field value.

0 Kudos