Handling Dates with Custom Validation in Workflow
I ran into this problem when creating a workflow for a standard time off type of request - there wasn't a way to force the 2nd date (in this case, the end date) to key off of the 1st, or start, date and therefore prevent the user from selecting something like 9/27/08 to 9/25/08 for his/her time off.
A coworker of mine helped me come up with a way of comparing the dates inside of the form itself, rather than looping out of the form. This way, the workflow would not progress if the end date was not greater than the start date and we can utilize custom validation to handle both the model and the error message. Consequently, the user would be required to fix the date issue right then and there.
There may be an easier/quicker way to handle this, but here's what we came up with:
In this example scenario, we will use what may be a typical structure of a user-submitted request form and a manager approval form (the latter being utilized solely for the sake of the information transmitting somewhere).
In the submission/request form, we will use a couple of labels and two date picker components, one for the "start date" and one for the "end date". The form utilizes a Submit button as its output.
We must have at least one component in the form set to Optional, so we will use the "end date" date picker component. It will be this component that will hold the custom validation.
- Double-click the "end date" date picker and on the Functionality tab of the Edit Component window, scroll down to the Validation section.
- Check Use Custom Validation and click the ellipse next to Custom Validation Model.
- In the embedded decision model that opens, add a Date Greater Than component.
- Add another End component and hook up your true and false links respectively.
- Name your true path End component something like "valid" and your false path "not valid".
- Double-click your Date Greater Than component and on the Evaluation tab, select your "end date" (EndDate in this example) for the First Date Variable Name.
- Select your "start date" (Start Date in this example) for the Second Date.
- Click OK then double-click your "valid" End component.
- On the Configuration tab, click the ellipse next to Mapping, and select Null Value.
- Click OK twice to get out of the component editor and then double-click the "not valid" End component.
- Click the ellipse next to Mapping, and select Create Value.
- Type a description for your validation - I typically use the error message as my description, so for this example, we will utilize "The end date must be greater than the start date." Type the same message into the Name field. Leave the Level as Warning.
- Click OK until you get out of the form and then out of the interaction model.