Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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.provide("DueDateValidation");

 dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes
 dojo.require("com.ibm.team.workitem.api.common.Status"); // To create a status object to return
 dojo.require("com.ibm.team.workitem.api.common.Severity"); // To create a severity for the status
 dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
 dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings


 (function() {
 
 var Status = com.ibm.team.workitem.api.common.Status;
 var WorkItemAttributes = com.ibm.team.workitem.api.common.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 = dojo.date.stamp.fromISOString(workItem.getValue(com.ibm.team.workitem.api.common.WorkItemAttributes.DUE_DATE));
     var duedate = GetDueDate.getTime().toString();
     var PHED = dojo.date.stamp.fromISOString(workItem.getValue("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.

0 votes

Comments

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

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?

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



3 answers

Permanent link
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.

0 votes


Permanent link
See https://jazz.net/forum/questions/220004/how-the-below-code-works-for-date-validation/220007

0 votes


Permanent link
I had to ban one answer as that had only philosophical content and a link to a resort page.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,935
× 152
× 34

Question asked: Apr 13 '16, 2:06 a.m.

Question was seen: 6,093 times

Last updated: Apr 14 '16, 2:33 a.m.

Confirmation Cancel Confirm