It's all about the answers!

Ask a question

How to validate fields so that a Due date is later than a Start date?

Ann Scanlan (622) | asked Mar 05 '14, 9:06 a.m.
I have customized a presentation and have two fields: a Start Date and a Due Date. I want the Start Date to mark the beginning of the project, and the Due Date to mark the end of the project (i.e. the date that the project is due).

I want to validate the Due Date field so that users cannot enter a date that is before the Start Date. For example, if the start date is 15 March 2014, I don't want someone to enter 12 March 2014 in the Due Date field.

Any ideas on how I can do this?

One answer

permanent link
Ralph Schoon (62.9k33645) | answered Mar 05 '14, 10:38 a.m.
edited Mar 05 '14, 10:40 a.m.
one possible approach would be attribute customization using JavaScript. See and Lab 5 for how to use attribute customization in general and using Java Script.

I have done that kind of validation already and it works.

Here example script code that does some of the computation needed:
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2011. All Rights Reserved.
 * Note to U.S. Government Users Restricted Rights:  
 * Use, duplication or disclosure restricted by GSA ADP Schedule 
 * Contract with IBM Corp. 

dojo.require(""); // To access the work item attributes
dojo.require(""); // To create a status object to return
dojo.require(""); // To create a severity for the status
dojo.require(""); // We need the date class from Dojo to compare two dates
dojo.require(""); // We need the stamp class to work with ISO date strings

(function() {
var Severity =;
var Status =;

var DateValidator = dojo.declare("org.example.DateValidator_30_days_later", null, {

    validate: function(attributeId, workItem, configuration) {
        var severity= "ERROR"; 
        var message= "Date must be at least 30 days from now"; 
       // Work Item new: not initialized - provides todays date. Once created provides the creation date 
        var beginDate ="")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate=;        
        // Compare the two dates returns negative value due to order
        var compare = -(, beginDate, "day"));
        if (compare>= 30) { // make sure endDate is not earlier than beginDate + 30
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message + " current value: [" +endDate + "] and difference is " + compare);

Please note, you need to activate the operational behavior to prevent from saving. See the workshop and the other link.

Your answer

Register or to post your answer.