Date comparision condition is not working while checking it second time
![]()
I have created a java script for date comparison which returns error if both dates are not same, while after creating condition i did a test on the condition but on first attempt condition behave as i expect but on the second attempt condition just returns the alert but not the ERROR.
I'm not able to figure out what's wrong with my code, if anyone could help me out to resolve this issue that would be great. Following is my code: dojo.provide("com.example.estimateddeploymentdatevalidation"); dojo.require("com.ibm.team.workitem.api.common.Severity"); dojo.require("com.ibm.team.workitem.api.common.Status"); (function () { var Severity = com.ibm.team.workitem.api.common.Severity; var Status = com.ibm.team.workitem.api.common.Status; dojo.declare("com.example.estimateddeploymentdatevalidation", null, { validate: function (attribute, workItem, configuration) { // require(["dojo/dom", "dojo/dom-style"], function (dom, domStyle) { var estimatedDate = dojo.date.stamp.fromISOString(workItem.getValue("arabbank.attribute.EstimatedDeploymentDate")); var deploymentDate = dojo.date.stamp.fromISOString(workItem.getValue("arabbank.attribute.DateTime")); if (estimatedDate != null && deploymentDate != null) { var diff = dojo.date.difference(estimatedDate, deploymentDate, "day"); //alert(diff); //alert(deploymentDate); if (diff != 0) { //alert("Inside"); var severity = "ERROR"; var message = "Estimated DeploymentDate & Deployment Date must be same"; alert(message); return new Status(Severity[severity], message); } } return Status.OK_STATUS; //}); } }); })(); |
One answer
![]()
The issue is not caused by your code, as I can easily reproduce the problem by using a simple "return" statement. I will rephrase the problem here:
If a script-based validator is present, it will be executed _once_ when the work item is loaded, and the red indicated is shown if an error message is returned. When the attribute value is changed, the validator is executed _twice_, and the red indicator is not shown regardless the valid state. This refers to the RTC Web client. The symptom in the RTC Eclipse client is slightly different - the indicator can appear briefly and disappear when the focus is moved to other attribute. I tested this in RTC 5.0.2 and could not find any defects similar to this. I think you can open a new defect for that. P.S. There are two things that you can improve your code - 1. add modules "dojo.date" and "dojo.date.stamp" to the code otherwise it will not work in RTC Eclipse client. 2. The logic is flawed and the code should return an error when either of the timestamp values is null (unless you make them mandatory somewhere else). |
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.