It's all about the answers!

Ask a question

Date Validation on RTC attributes


0
1
Ashwath G (6623550) | asked Mar 02 '15, 1:32 p.m.
edited Mar 02 '15, 1:36 p.m.
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

One answer



permanent link
Ralph Schoon (63.1k33645) | answered Mar 05 '15, 4:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Your answer


Register or 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.