Validator javascript to validate date has syntax error
![]()
I am using RTC 5.0.2/Eclipse client 5.0.2 as well.
Referring to https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation and I tried the below javascript to validate the custom attribute FixedDate(timestamp type) to be set later than creation date. dojo.provide("org.example.DateValidator"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); //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("org.example.DateValidator", null, { validate: function(attributeId, workItem, configuration) { //custom attribute FixedDate has id fixeddate var fixdate=dojo.date.stamp.fromISOString(workItem.getValue("fixeddate")); var createdate=dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE)); // Compare the two dates and make sure fixeddate is not earlier than creation date if (dojo.date.compare(fixdate, createdate) >= 0) { console.log("Fixed date set >= create date"); return Status.OK_STATUS; } else { console.date(""Fixed date must be set earlier"); return new Status("ERROR","Fixed date must be set later than Creation Date"); } } }); })(); From source code, I see <customAttributes category="com.ibm.team.workitem.workItemType.task"> <customAttribute id="fixeddate" name="FixedDate" type="timestamp"/> </customAttributes> <presentation kind="com.ibm.team.workitem.kind.separator"/> <presentation attributeId="fixeddate" kind="com.ibm.team.workitem.kind.timestamp"/> <attributeDefinition id="fixeddate" name="FixedDate" type="timestamp"> <validator providerId="com.ibm.team.workitem.valueproviders.VALIDATOR._XeBK0G54EeaYaaCv-IsPKg"/> <dependsOn id="com.ibm.team.workitem.attribute.creationdate"/> </attributeDefinition> I tried to test the code but the log always shows: syntax error and !MESSAGE Error invoking validator com.ibm.team.workitem.valueproviders.VALIDATOR._XeBK0G54EeaYaaCv-IsPKg !STACK 0 com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'org.example.DateValidator' is not a constructor I went through the code many times but could not pinpoint where the syntax error is from. Can anyone please shed some lights on this error? Thank you very much. |
Accepted answer
One other answer
![]()
Dinesh Kumar B (4.1k●4●13)
| answered Aug 30 '16, 7:32 a.m.
JAZZ DEVELOPER edited Aug 30 '16, 7:50 a.m.
Hi Don,
The following line has a syntax error, the double double quotes at the start :) console.date(""Fixed date must be set earlier"); also, it should be console.log instead of console.date isn't it!!! hope this helps. Regards Dinesh Comments Hi, Dinesh
|
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.