Hi,
I am trying to delete a feature based on the length of time that passes. I am hoping to fully automate a project that we are working on so that if a certain number of days pass, then that particular feature gets deleted. I hope someone can assist. I am relatively new to attribute rules but the few that I have implemented, it has helped significantly with automating tasks.
var From = Date($feature.OutageEnd)
var To = Date(Now())
var DaysAfterOutage = DateDiff(To, From, 'days')
//Constants for defining which features to delete//
var UniqueID = $feature.GlobalID
//Define which features to delete after a given amount of time//
if (DaysAfterOutage >= 7){
return {
'edit':[
'deletes':[
{UniqueID}
]
]
}
}
Any help on this would be greatly appreciated.
Solved! Go to Solution.
Other than scheduling a python script to run periodically, I know of no way to do that completely automatically.
I think the Attribute Rule approach comes pretty close. All you have to do to execute it is insert a new feature or update an existing one.
There are a number of things that would be good in this scenario but aren't possible:
So fully automated deletion won't be possible. But there are a few things that could make it easier:
return IIF(DateDiff(Now(), $feature.OutageEnd, "days") >= 7, "red", "blue")
// Calculation Attribute rule on your feature class
// Some editable field
// Triggers: Insert, Update
// Exclude: True
// get all entries of your feature class
var fs = FeatureSetByName($datastore, "FeatureClass")
// if OutageEnd can be null, filter these values out
fs = Filter(fs, "OutageEnd IS NOT NULL")
// You could filter for the date, but the sql depends on your dbms, so I'm not going to do that. Instead, I'm going to test each feature using Arcade.
var deletes = []
for(var f in fs) {
if(DateDiff(Now(), f.OutageEnd, "days") >= 7) {
Push(deletes, {"globalID": f.GlobalID})
}
}
return {
"result": $feature.YourReturnField,
"edit": [
{
"className": "FeatureClass",
"deletes": deletes
}
]
}
Thanks @JohannesLindner,
I was really hoping that deletions on the fly were possible. I know it is very easy to do using python, since I have built several tools to delete an existing feature if it already exists. I am surprised, however, that automated deletion isn't possible even though attribute changes can be made on the fly. So I assumed that there was a way to set up a rule to automatically delete a record if the criteria were met.
Other than scheduling a python script to run periodically, I know of no way to do that completely automatically.
I think the Attribute Rule approach comes pretty close. All you have to do to execute it is insert a new feature or update an existing one.