It's all about the answers!

Ask a question

Validator javascript to validate date has syntax error

Don Yang (7.7k21110138) | asked Aug 30 '16, 6:17 a.m.
I am using RTC 5.0.2/Eclipse client 5.0.2 as well.
Referring to
and I tried the below javascript to validate the custom attribute FixedDate(timestamp type) to be set later than creation date.

dojo.require(""); // We need the date class from Dojo to compare two dates
dojo.require(""); // We need the stamp class to work with ISO date strings

(function() {
//var Severity =;
var Status =;
var WorkItemAttributes=;
dojo.declare("org.example.DateValidator", null, {

    validate: function(attributeId, workItem, configuration) {
         //custom attribute FixedDate has id fixeddate
        // Compare the two dates and make sure fixeddate is not earlier than creation date
        if (, createdate) >= 0) {
            console.log("Fixed date set >= create date");
            return Status.OK_STATUS;
        } else {
  ""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="">
                    <customAttribute id="fixeddate" name="FixedDate" type="timestamp"/>

<presentation kind=""/>
                    <presentation attributeId="fixeddate" kind=""/>

<attributeDefinition id="fixeddate" name="FixedDate" type="timestamp">
                        <validator providerId=""/>
                        <dependsOn id=""/>

I tried to test the code but the log always shows:
 syntax error and
!MESSAGE Error invoking validator
!STACK 0 '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

permanent link
Donald Nong (14.5k414) | answered Aug 30 '16, 9:12 p.m.
edited Aug 30 '16, 9:12 p.m.
There are a few problems with the implementation.
1. Double double-quotes, as mentioned earlier.
2., 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

Don Yang commented Aug 31 '16, 1:36 a.m.

Thanks Donald.
I tested that before and just now and got the same problem on my machine.
Tried to clear server and broswer cache and different browser, browser debug always returns the same error. I then tried with different version and it works. As it works on your 502, I believe something is wrong with my machine's v5.0.2.

Davyd Norris commented Apr 15 '19, 3:01 a.m. | edited Apr 15 '19, 3:03 a.m.
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: 'org.example.DateValidator' is not a constructor

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

permanent link
Dinesh Kumar B (4.1k413) | answered Aug 30 '16, 7:32 a.m.
edited Aug 30 '16, 7:50 a.m.
Hi Don,

The following line has a syntax error, the double double quotes at the start :)""Fixed date must be set earlier");

also, it should be

instead of
isn't it!!!

hope this helps.


Don Yang commented Aug 30 '16, 7:32 p.m. | edited Aug 30 '16, 7:33 p.m.

Hi, Dinesh

Thank you very much for pointing that out, that's my silly mistake. console.log was added to see if I can find any clues why the code does not work as expected. So the code still does not work even though syntax error is not seen now. I still see
'org.example.DateValidator' is not a constructor
error in the log, and when I add a fixed date to be earlier than the creation date, I can save the work item which means the validation is not properly done on the custom attribute. Did you happen to try the code and do you see the logic work in your environment?
I am wondering what else is a problem in this code.

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.