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

Date Validation on RTC attributes

Hello,

We have a requirement to implement the date validation on RTC date attributes.

There are two custom date attributes say Analysis Start Date and Analysis End Date . Never the End Analysis Date should be lesser than Start Date. And it should throw the error if the above condition is not met while save operation on WI.
We wrote a Validation script and created a validator applied on the attribute . But its not working , its throwing an error message on end date if date is less than start date , but it is able to save the Workitem.

Could you please verify the below code and let us know how to throw error and not to save WI.

dojo.provide("com.ibm.team.workitem.DateValidator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.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 Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("com.ibm.team.workitem.DateValidator", null, {

    validate: function(attributeId, workItem, configuration) {
 
           var severity = "ERROR";
            var message = "Start Date should be less than End Date";
 
  // Get the begin date attribute from the configuration and make a Date object from it
       var beginDateId = workItem.getValue("plannedanalstart");
        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue(beginDateId));
       
        // Get the current attribute's value and make a Date object from it
        var endDateId = workItem.getValue("plannedanalend");
        var endDate = dojo.date.stamp.fromISOString(workItem.getValue(endDateId));
       
        // 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 {
            return new Status(Severity[severity], message);
        }
    }
});
})();


Thank you...!


Ashwath

1

0 votes



One answer

Permanent link
Please see https://jazz.net/forum/questions/175331/how-do-validators-work on how to configure the operational behavior to prevent saving on error.

I can't see any obvious problem with the script.

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
× 6,117

Question asked: Mar 02 '15, 1:32 p.m.

Question was seen: 4,956 times

Last updated: Mar 05 '15, 4:42 a.m.

Confirmation Cancel Confirm