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
There are a few problems with the implementation.
1. Double double-quotes, as mentioned earlier. 2. console.date(), also as mentioned earlier. 3. The last statement should have been return new Status(Severity["ERROR"],"Fixed date must be set later than Creation Date");Of course you need to uncomment the two related lines to make it work. The Severity class seems to have been deliberately taken out, why? 4. If you only see the error right after entering the value for "Fixed Date", but submission still goes ahead, make sure that you add the "Attribute Validation" precondition in the Operational Behavior section. Don Yang selected this answer as the correct answer
Comments
Don Yang
commented Aug 31 '16, 1:36 a.m.
Thanks Donald.
I know this is quite old, but I am also seeing the same errors in the ccm server logs from my customisations - however my scripts are working fine as far as I can see.If you look carefully at the error though:
you can see that these errors are generated when the JavaScript engine on the **server** tries to execute the script. The same script is also executed in the web client and this is when it works.
So this appears to be some sort of bug in the RTC JavaScript engine, or perhaps an older version of the engine is running in the server compared to the various web clients?
|
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.