Select to view content in your preferred language

Arcade Expression to dynamically delete points when exceeds End Date

1186
3
Jump to solution
08-18-2023 02:38 AM
Labels (1)
JonDolphin
Emerging Contributor

I have a point layer used for request work permits and I created a Web Application. I symbolized points using Arcade expression according to the expire date. But now user wants to expired points to be deleted. Does someone has some idea how to do it and help me? Thank you!

Currently my Arcade looks as in attachment.

 

 

0 Kudos
1 Solution

Accepted Solutions
berniejconnors
Frequent Contributor

I really like Johannes ' idea to leave Expired points unsymbolized. 

Otherwise I would suggest a scheduled Python script that would examine the age of all the points and remove or archive the expired points.  To maintain a history I think it would be best to archive the expired points or leave them unsymbolized.   To archive the points your Python script should copy the points to a new feature class before deleting them.

Bernie.

View solution in original post

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Your expression can be simplified:

var time1 = Date($feature.enddate)
var dd = DateDiff(time1, Now(), "days")

return When(
  dd <= 0, "Inactive",
  dd <= 5, "5 days or less to expire",
  "Active"  
)

 

 

You have a few possibilities:

  • Just don't symbolize expired points. They will still be in the table, but won't show up in the map.
  • If your actual data is in a database, you can use an Attribute Rule (doesn't work for layers hosted in AGOL). You could create an Attribute Rule on your point featureclass like the script below. That will delete all expired points every time you add a new point.
// Calculation Attribute Rule on your poit fc
// triggers: Insert
// field: empty
// exclude from application evaluation

var deletes = []
for(var f in $featureset) {
  var dd = DateDiff(f.DateField1, Now(), "days")  // replace with the name of your date field
  if(dd <= 0) {
    Push(deletes, {globalID: f.GlobalID})
  }
}
return {
  edit: [{
      className: "TestPoints",  // replace with the name of your point fc
      deletes: deletes
    }]
  }

 

  • You could also write a Python script that deletes all expired points. You can run that script manually or have it run automatically every day or so.

 


Have a great day!
Johannes
JonDolphin
Emerging Contributor

Hi Johannes, many thanks for your suggestions. I used the strategy to not showing expired permits but user is not pleased. So I'll try the python option which looks a good option.

0 Kudos
berniejconnors
Frequent Contributor

I really like Johannes ' idea to leave Expired points unsymbolized. 

Otherwise I would suggest a scheduled Python script that would examine the age of all the points and remove or archive the expired points.  To maintain a history I think it would be best to archive the expired points or leave them unsymbolized.   To archive the points your Python script should copy the points to a new feature class before deleting them.

Bernie.

0 Kudos