Select to view content in your preferred language

Date Range Domain End Date of Current Date

135
3
3 weeks ago
Labels (2)
GeorgeNewbury
Frequent Contributor

Good morning. I'm pretty sure the answer to this is 'no, good idea, go put it in the idea section'.

I would like to have a Range Domain on a date field that has a maximum value of the present. So today the maximum value is 8/13/2025, tomorrow the maximum value is automatically adjusted to 8/14/2025. I'm not too concerned about the time component, but for arguments sake I should be able to set it as local or utc time.  

Use case is an additional check to make sure that the data wasn't fat fingered in wrong. Of course I could check it in a variety of other ways, but this seems to be a fairly straight forward approach to validation that a date isn't in the future. 

 

Thanks!

George

0 Kudos
3 Replies
Robert_LeClair
Esri Esteemed Contributor

"No, good idea, go put it in the idea section."

In all seriousness, ArcGIS Pro does not support dynamic domains natively so some type of scripting would be required for this type of functionality.  I wonder if an attribute rule of some sort would work?

Update:  I created an immediate calculation rule for inserts and updates to the feature class where the date calculation is based upon another fields attribute value of 'Active' vs 'Inactive'.  The arcade expression would be something like this:  

if ($feature.Status == 'Active') {
return Now();
} else {
return Null;
}

So if you add a new feature it calculates today's date - same if you move the feature.  I also had to use default attribute values in the feature template where Status is set to Active for the insert trigger to work.  Would this work?

0 Kudos
VinceE
by
Frequent Contributor

I like to use "Calculation" style attribute rules as constraints and/or validators (rather than using either of those specifically named flavors of Attribute Rules, but your opinions may vary).

Here is a "Date" field called "A_Date" where I've entered a date in the past, today's date, left a NULL value, and then finally entered a date in the future (8/15/2025 at the time of writing this). This rule accepts the first three, and fails with a specific error message when a future date is entered.

This is sort of hack together "dynamic" domain, which seems like what you want. Using similar logic, I think you could also set something up where you only allow "yesterday," "today," or "tomorrow," that sort of dynamic date range scenario.

I believe there are time zone options available in Arcade too, if you want to go down that road.

// My date field.
var enteredDate = $feature.A_Date

// Get current date using built-in function.
var curDate = Now()

// If entered date is in the future, block it from being entered. Return message to user.
if (enteredDate > curDate) {
    return {
        "errorMessage": "This value is in the future, and therefore invalid."
    }
}

invalid_date.png

 

0 Kudos
VinceE
by
Frequent Contributor

Here's a very unnecessarily verbose version of this, but I use this basic template structure a lot for these "constraint" or domain type on-the-fly validation checks. You can incorporate several different checks and error messages, depending on what you're checking.

/*
SCRIPT SUMMARY:
AUTHOR: 
DATE: 
*/
//---------------------------------------------------------------------//
// INPUTS
var enteredDate = $feature.A_Date

// OUTPUT FIELDS
var dateFldName = "A_Date"

//---------------------------------------------------------------------//
// FUNCTIONS
function dateValidate(dateVal) {
    // Initialize results dictionary
    var result = Dictionary("VALUE", dateVal, "ERROR", null)

    // Null is fine, return value as-is
    if (IsEmpty(dateVal)) {
        return result
    }

    // CHECK 1: if entered date is in the future, return error
    var curDate = Now()
    if (dateVal > curDate) {
        result["ERROR"] = "This date is in the future, and therefore invalid."
        return result
    }

    // Otherwise return value as-is
    return result
}

//---------------------------------------------------------------------//
// MAIN
var fldUpdates = Dictionary()

// Validate using custom function.
var result = dateValidate(enteredDate)

// If error found, return message and block the edit
if (!IsEmpty(result["ERROR"])) {
    var msg =  `\n\n• SUBMITTED VALUE: '${Text(result["VALUE"], "MM/DD/YYYY")}'`
               + `\n\n• ERROR: ${result["ERROR"]}`
               + `\n\n• GENERAL NOTE: Date must be today or earlier.`

    return {"errorMessage": msg}
}
// Else, update field value (in this case, return the value as-is)
else {
    fldUpdates[dateFldName] = result["VALUE"]
}

return {"result": {"attributes": fldUpdates}}
0 Kudos