It's all about the answers!

Ask a question

Date validation: Cannot read property "DUE_DATE"


Akshay Panchakshari (37128) | asked Jun 09 '16, 10:07 a.m.
edited Jun 09 '16, 10:18 a.m.

I am trying to do date validation.Two fileds are involved here one is in-build "Due date" and the second is the custom field extended date. But when the script is triggered i get the below error:

!ENTRY com.ibm.team.workitem.common 4 0 2016-06-09 19:31:57.154
!MESSAGE Error invoking validator com.ibm.team.workitem.valueproviders.VALIDATOR._e6trIC4oEeaDz9yQi8uE-Q
!STACK 0
com.ibm.team.repository.common.TeamRepositoryException: Unexpected exception type
 at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.handleException(ScriptAttributeValueProvider.java:281)
 at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.validate(ScriptAttributeValueProvider.java:149)
 at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValidator.validate(AttributeValueProviderRegistry.java:152)
 at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.validate(AttributeImpl.java:928)
 at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 at java.lang.reflect.Method.invoke(Method.java:611)
 at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
 at com.sun.proxy.$Proxy41.validate(Unknown Source)
 at com.ibm.team.workitem.client.internal.util.WorkItemEventResolver$InternalBackgroundJob.resolve(WorkItemEventResolver.java:261)
 at com.ibm.team.workitem.client.internal.util.WorkItemEventResolver$InternalBackgroundJob.runProtected(WorkItemEventResolver.java:89)
 at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot read property "DUE_DATE" from undefined (date-validator.js#24)
 at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
 at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
 at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3563)
 at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3582)
 at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3595)
 at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1381)
 at org.mozilla.javascript.gen.c19._c2(date-validator.js:24)
 at org.mozilla.javascript.gen.c19.call(date-validator.js)
 at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
 at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
 at org.mozilla.javascript.gen.c19.call(date-validator.js)
 at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler$1.run(AbstractInvocationHandler.java:160)
 at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74)
 at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler.invoke(AbstractInvocationHandler.java:156)
 at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invokeGeneric(AbstractInvocationHandler.java:141)
 at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:95)
 at com.sun.proxy.$Proxy55.validate(Unknown Source)
 at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.validate(ScriptAttributeValueProvider.java:147)
 ... 11 more

Below is my javascriot code for the same. --

dojo.provide("org.example.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;
var DateValidator = dojo.declare("org.example.DateValidator", null, {

    validate: function(attributeId, workItem, configuration) {
         console.log("hi");
        // Get the configuration parameters about the severity and error message of this validator
        var severity= configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name);
        var message= configuration.getChild("parameters").getStringDefault("message", "");
        console.log(message);
        // Get the Due date attribute
  var dateRequiredBy=dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));

         // Get the current attribute's value and make a Date object from it
  var extendedDate=dojo.date.stamp.fromISOString(workItem.getValue(attributeId));
        console.log(dateRequiredBy);
  console.log(extendedDate);
  // Compare the two dates and make sure extendedDate is not earlier than dateRequiredBy
  //If the dateRequiredBy > extendedDate = +ve else -ve
        if (dojo.date.compare(dateRequiredBy, extendedDate) <= 0) {
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message);
        }
    }
});
})();

The above code was workin fine in RTC version 3.0.1. recently i have upgraded to RTC 4.0.3 and the script does't work here. WorkItemAttributes.DUE_DATE is not supported or changed in RTC 4.0.3

Please advice what is the issue here ?

Thanks 

One answer



permanent link
Akshay Panchakshari (37128) | answered Jun 09 '16, 10:31 a.m.

Hi All!

Found the issue!!

the below line of code was missing-

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

Thanks

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.