It's all about the answers!

Ask a question

RTC script based validation: Due Date should be greater than equal to Current Date


Deepali Deshmukh (8913759) | asked May 02 '17, 1:54 a.m.
edited May 02 '17, 2:00 a.m.
I have implemented java scrip in RTC workitem for date validation. It should validate the due date should be greater than or equal to current date(System generated Date). 
 I have written the script for validation. when I am reading the Due Date in the script it shows me null. below is the script. 
Please help me if I have missed in script. 

Thanks 
Deepali Nigade


dojo.provide("com.ibm.team.workitem.DueDateValidation"); 
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; 

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

    validate: function(attributeId, workItem, configuration) { 
  
           var severity = "ERROR"; 
           var message = "Due Date should be greater than Current Date"; 
           
  var DueDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.duedate"));
  var GetCurrentDate = new Date(); 
  var CurrentDate = dojo.date.stamp.toISOString(GetCurrentDate, {milliseconds:true, zulu:true}); 
         
console.log("Due date" + DueDate) ;
console.log("Current date" + CurrentDate) ;
         
if(CurrentDate != null && DueDate != null) { 
        if (dojo.date.compare(DueDate, CurrentDate) >= 0) { 
console.log("Due date" + DueDate) ;
            return Status.OK_STATUS; 
        } 
else { 
console.log("Due date" + DueDate) ;
            return new Status(Severity[severity], message); 
        } 
}
    } 
}); 
})(); 

Log Details
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2017-05-02 11:16:56.272
!MESSAGE LOG: 'Due datenull'

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2017-05-02 11:16:56.272
!MESSAGE LOG: 'Current date2017-05-02T05:46:56.272Z'

!ENTRY com.ibm.team.workitem.common 4 0 2017-05-02 11:16:56.272
!MESSAGE Error invoking validator com.ibm.team.workitem.valueproviders.VALIDATOR._dKCw0CvmEeezg6uHToykVw
!STACK 0
java.lang.NullPointerException
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getSeverity(ScriptAttributeValueProvider.java:250)
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.validate(ScriptAttributeValueProvider.java:152)
at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValidator.validate(AttributeValueProviderRegistry.java:171)
at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.validate(AttributeImpl.java:930)
at sun.reflect.GeneratedMethodAccessor133.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.$Proxy35.validate(Unknown Source)
at com.ibm.team.workitem.client.internal.util.WorkItemEventResolver$InternalBackgroundJob.resolve(WorkItemEventResolver.java:265)
at com.ibm.team.workitem.client.internal.util.WorkItemEventResolver$InternalBackgroundJob.runProtected(WorkItemEventResolver.java:93)
at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered May 02 '17, 2:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited May 02 '17, 2:49 a.m.

 You get a null pointer exception, because all the attribute ID's you are using are incorrect. Due to a really annoying error in the RTC Eclipse client, it shows all the built in attributes with an incorrect ID using the prefix com.ibm.team.workitem.attribute


Instead of the ID shown in Eclipse com.ibm.team.workitem.attribute.duedate , the attribute ID is actually dueDate. You can find the attribute ID's in the RTC Web project area administration page (Work Items -> Types&Attributes). Also https://jazz.net/wiki/bin/view/Main/AttributeCustomization lists official constants for the supported attributes. 

Deepali Deshmukh selected this answer as the correct answer

2 other answers



permanent link
Ralph Schoon (63.1k33645) | answered May 02 '17, 6:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I would suggest to use a search engine and to search for how to do date comparisons in Javascript. dojo.date.difference has worked for me as an example. 


permanent link
Deepali Deshmukh (8913759) | answered May 02 '17, 4:28 a.m.

 Thank You Ralph its working!!


 I am getting the due date value but now the compare condition is not working. 
For Due Date -
           var DueDateid = dojo.date.stamp.fromISOString(workItem.getValue("dueDate"));
           var DueDate = DueDateid.getTime().toString(); 
For Current date - 
   var GetCurrentDate = new Date();
   var CurrentDate = GetCurrentDate.getTime().toString(); 
   
It gives error if the due date is less than current date but it also shows error if due date is equal to current date. Below is the if condition 
  if (dojo.date.compare(DueDate, CurrentDate) >= 0)

also tried using if ((DueDate > CurrentDate) || (DueDate == CurrentDate))

Do I need to convert the date in some another format ?

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.