Select to view content in your preferred language

Attribute rule to change domain value based on date

707
2
Jump to solution
03-23-2022 01:30 AM
PetronellaHauptmann1
Emerging Contributor

Hi everyone.

I'm trying to create an attribute rule that changes a domain value when a specific date is passed.

So the main problem I'm trying to solve is this:
When a feature is created, the feature gets domain code 105. When the feature is up for review in a process, the administrator changes the domain code from 105 to a value between 100-104 and sets a end date in another field. When the end date is passed I want the domain code to change back to 105.PetronellaHauptmann1_0-1648024129484.png

Here is the Arcade-code I've been working on. It validates just fine, but when I execute the rule the domain value does not change. 

var skedenr = $feature.Skede
var utstallningsdatum = $feature.Utstallningsdatum
var dagensdatum = Today()
var skede = IIF(skedenr != 105, '1', '3')
var datum = DateDiff(utstallningsdatum, dagensdatum)
var datums = IIF(datum <= 0, '1', '3')
var sant = IIF(skede + datums == 2, 105, skedenr)
return sant

Super grateful for help!

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

It sounds as if you want the field to update itself when the specified date is passed. That is not possible. An Attribute Rule only triggers when you actively do something to a feature (insert/update/delete), they are not checked continually.

What you can do is create a Batch Attribute Rule. These are rules that don't trigger on insert/update/delete, but are evaluated when the user wants.

 

var skedenr = $feature.IntegerField
var utstallningsdatum = $feature.DateField

if(skedenr == null || skedenr == 105) {
  return 105
}
if(utstallningsdatum == null) {
  return skedenr
}
var datum = DateDiff(utstallningsdatum, Today())
return IIF(datum <= 0, 105, skedenr)

 

 

My test features before and after evaluating the rule (on 2022-03-24)

BeforeAfter
JohannesLindner_0-1648128567268.pngJohannesLindner_1-1648128647131.png

 

Notes:

  • The second row didn't get changed because there was no date supplied.
  • The last row didn't get changed because DateDiff(datevalue, Today()) returned 1 hour. Might be related to daylight saving time, I don't know. This is a file gdb, did not test on enterprise.
    • To change this behavior, you can replace the last 2 lines with this:

 

var datum = DateDiff(utstallningsdatum, Today(), "hours")
return IIF(datum <= 1, 105, skedenr)

 

 

 

 


Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

It sounds as if you want the field to update itself when the specified date is passed. That is not possible. An Attribute Rule only triggers when you actively do something to a feature (insert/update/delete), they are not checked continually.

What you can do is create a Batch Attribute Rule. These are rules that don't trigger on insert/update/delete, but are evaluated when the user wants.

 

var skedenr = $feature.IntegerField
var utstallningsdatum = $feature.DateField

if(skedenr == null || skedenr == 105) {
  return 105
}
if(utstallningsdatum == null) {
  return skedenr
}
var datum = DateDiff(utstallningsdatum, Today())
return IIF(datum <= 0, 105, skedenr)

 

 

My test features before and after evaluating the rule (on 2022-03-24)

BeforeAfter
JohannesLindner_0-1648128567268.pngJohannesLindner_1-1648128647131.png

 

Notes:

  • The second row didn't get changed because there was no date supplied.
  • The last row didn't get changed because DateDiff(datevalue, Today()) returned 1 hour. Might be related to daylight saving time, I don't know. This is a file gdb, did not test on enterprise.
    • To change this behavior, you can replace the last 2 lines with this:

 

var datum = DateDiff(utstallningsdatum, Today(), "hours")
return IIF(datum <= 1, 105, skedenr)

 

 

 

 


Have a great day!
Johannes
0 Kudos
PetronellaHauptmann1
Emerging Contributor

It works just fine.

I am so grateful for your help!

0 Kudos