It's all about the answers!

Ask a question

How to compare two Date attributes in a script-based validator?

Arjun Pande (3614) | asked Apr 13 '16, 2:06 a.m.
converted to question Apr 14 '16, 1:04 a.m. by Donald Nong (14.5k414)

Hi Ralph,

I need to write a dojo script where I can compare 2 dates, one is IBM out of the box field due date and other is system current date. I am writing a validator script where users will not be allowed to enter the Due date < Current Date. Due Date can be equal to or greater than current date. Below is the dojo script for the same.


 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 Status =;
 var WorkItemAttributes =;

 var DateValidator = dojo.declare("DueDateValidation", null, {

     validate: function(attributeId, workItem, configuration) {
         var severity = "ERROR";
         var message = "Due Date cannot be less then Current Date";
     var GetCurrentDate = new Date();
         var CurrentDate = GetCurrentDate.getTime().toString();
     var GetDueDate =;
     var duedate = GetDueDate.getTime().toString();
     var PHED ="HandoverPlannedEndDate"));
     var StringPHED = PHED.getTime().toString();

         // Compare the two dates and make sure DueDate is not earlier than CurrentDate
         if ((workItem.getValue(WorkItemAttributes.TYPE)=="change_request") && (duedate >= CurrentDate)) {
             return Status.OK_STATUS;
         }else {
             return new Status(Severity[severity], message);

I am using formal process management template and the CLM version is 6.0. Please let me know your thoughts on this. Any help is appreciated. Thanks.

Donald Nong commented Apr 14 '16, 1:05 a.m.

Posting a question as an answer to in an old post does not get you anywhere. I've converted it to a question now.

Donald Nong commented Apr 14 '16, 1:16 a.m.

Your script is quite messy, to say the least. Why do you convert a String to a Date, and then to a String, and finally compare two String values? What is the purpose of the variables PHED and StringPHED? You did not say whether the script works for you or not - have you tried it?

Ralph Schoon commented Apr 14 '16, 2:33 a.m.

Posting on an old question is not a good idea and trying to direct questions in specific users directions neither.

3 answers

permanent link
Arjun Pande (3614) | answered Apr 14 '16, 1:35 a.m.
The template I am using is Formal Process Management Template and the RTC version is 6.0. So the id's of the due date comes from that template.

permanent link
Ralph Schoon (62.3k33643) | answered Apr 14 '16, 2:08 a.m.

permanent link
Ralph Schoon (62.3k33643) | answered Apr 14 '16, 2:31 a.m.
I had to ban one answer as that had only philosophical content and a link to a resort page.

Your answer

Register or to post your answer.