It's all about the answers!

Ask a question

End date should be greater than start date


Amit Girme (1131723) | asked Feb 04 '13, 9:06 a.m.
edited Apr 02 '13, 4:01 a.m. by Ralph Schoon (56.3k23642)
 Hi All,

I have created two custom attributes start date and end date. When i create WI My end date should be greater than Start date.

for eg start date - 15/02/2013    then end date - 16/02/2013  

If my end date is less then 15/02/2013 then i should get error message.

How can i do this??

Regards,
Amit

2 answers



permanent link
Eric Jodet (6.3k5100120) | answered Feb 04 '13, 9:13 a.m.
JAZZ DEVELOPER
Hello Amit,
check the date validator sample here:
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation

Thanks.
Eric.

Comments
Amit Girme commented Feb 04 '13, 9:33 a.m.

Hey Eric,


Thanks for your reply.


i went through that links and tried to resolve it , but i didn't work for me as i am new to javascript

Do you have working script for the same?
it will be very helpfull for me.

regards,
amit


Eric Jodet commented Feb 04 '13, 10:02 a.m.
JAZZ DEVELOPER

Hello Amit,
sample js below (no guarantee it works - this is just a sample for which you'll have to fill the blanks, adapt..)
However, hope it will help.
Thanks.
Eric.


permanent link
Eric Jodet (6.3k5100120) | answered Feb 04 '13, 10:02 a.m.
JAZZ DEVELOPER

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

    validate: function(attributeId, workItem, configuration) {
        var severity = "ERROR";
        var message = "your error msg here";

        var wi_type = workItem.getValue(WorkItemAttributes.TYPE);
        if (wi_type != "your work item type here") {
                // we may want to restrict the validation to a given type only
                return Status.OK_STATUS;
        }

        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("your begin date"));
        var endDate= dojo.date.stamp.fromISOString(workItem.getValue("your end date"));
               
        // Compare the two dates and make sure endDate is not earlier than beginDate
        if (dojo.date.compare(endDate, beginDate) >= 0) {
            return Status.OK_STATUS;
        }else if((beginDate == null) && (endDate == null)) {
            return Status.OK_STATUS;
        }else if((beginDate != null) && (endDate == null)) {
            return Status.OK_STATUS;
        }else {
            return new Status(Severity[severity], message);
        }
    }
});
})();

Your answer


Register or to post your answer.