Hello, are there any ways to prevent a user from entering an end date that is earlier than a start date? My example is for custom date fields called "Planned Work Start" and "Planned Work End". When those dates are both filled out, another custom field called "Planned Work Duration" is automatically filled out by a process. If the user enters an end date that is before the start date, the number is negative. It should not be allowed to happen.
How could I force the user to enter an end date that has to be after the start date? Is there an error I can make the user see?
The only way I can think of is to have a process with a gateway with a conditional flow with the condition "planned work end < planned work start" then it deletes the end date and sends the user an email telling them to try again. Are there any better ways?
You can do this using field validation. There is an article in the academy that covers exactly the scenario you're after (ensuring one date field is after another date field).
I got it to work, (yay) however, I have THREE independent sets of dates on the same page that I want to use this validation for, which is complicating things. I tried to copy the code and paste it twice and just edit the date columns being used for start and end date, but I'm given the JS error "duplicate function" being used. I'm sure I can accomplish my task using something like else if statements, however I'm not very well versed in JS. Could you provide any advice to get me pointed in the right direction? otherwise I'll be trial-and-erroring for a while until I figure it out. I'll post the code that worked for the one set of dates, and the code that gave me the error when I tried to copy it for the next set of dates.
This worked:
// Validate method for values in the [Planned Work End] and [Planned Work Start] columns.
dueDateValidator: function() {
// Variable for storing a validation error message.
var invalidMessage = "";
// Checking values in the [Planned Work End] and [Planned Work Start] columns.
if (this.get("VvtPlannedWorkEnd") < this.get("VvtPlannedWorkStart")) {
// If the value of the [Planned Work End] column is less than the value
// of the [Planned Work Start] column a value of the localizable string is
// placed into the variable along with the validation error message
Just wanted to share that a coworker who is excellent with Java Script helped me figure this out. For anyone else that is faced with the same issue where you have multiple sets of dates to validate on the same page, here is what we did:
// Validate method for values in the [Planned Work End] and [Planned Work Start] columns.
dueDateValidator: function() {
// Variable for storing a validation error message.
var invalidMessage = "";
// Checking values in the [Planned Work End] and [Planned Work Start] columns.
if (this.get("VvtPlannedWorkEnd") < this.get("VvtPlannedWorkStart")) {
// If the value of the [Planned Work End] column is less than the value
// of the [Planned Work Start] column a value of the localizable string is
// placed into the variable along with the validation error message