[DateTime validation rule] I cant get a minimum value validation rule to work...

3
Hi there, I'd like to have your advice. I have a simple (test)project, in which I have 1 entity with an attribute of datatype datetime. I also have a validation rule that enforces to enter only datetimes that are after the year 2000 I have tried a lot of dateformats like 1-1-2000 or with datetime or whatever... I however keep getting exceptions in my console like below... Please advice: is it a bug or a wrong syntax of my validation-rule? Current validationrule value is: "range: greater than or equal to....": 2/15/2012 12:00 AM and the exception is com.mendix.core.CoreException: Exception occurred in action '{"type":"ChangeAction","changes":"{Name=lkj, myDatetime=1330038000000}"}', all database changes executed by this action were rolled back at com.mendix.core.actionmanagement.CoreAction.c(SourceFile:485) Caused by: java.lang.IllegalArgumentException: Invalid format: "2/15/2012 12:00 AM" is malformed at "/15/2012 12:00 AM" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:683) at ir.a(SourceFile:296) at ir.a(SourceFile:289) at hC.b(SourceFile:430) at hC.a(SourceFile:172) at hG.setValue(SourceFile:234) at com.mendix.core.objectmanagement.member.MendixDateTime.parseValueFromString(SourceFile:58) at hF.setValue(SourceFile:273) at gK.a(SourceFile:308) at gK.a(SourceFile:120) at gK.executeAction(SourceFile:53) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:48) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:434) at hg.b(SourceFile:155) at com.mendix.core.Core.change(SourceFile:541) at fV.execute(SourceFile:58) at iD.a(SourceFile:306) at iD.a(SourceFile:235) at iD.processRequest(SourceFile:179) at iG.a(SourceFile:71) at com.mendix.core.MxRuntime.processRequest(SourceFile:842) at com.mendix.m2ee.server.handler.RuntimeHandler.handle(RuntimeHandler.java:43) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113) at org.eclipse.jetty.server.Server.handle(Server.java:334) at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559) at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1007) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:747) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:209) at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436) at java.lang.Thread.run(Thread.java:662) Thanks for the advice already! Edit in reply to Pieter / Ronald thanks for your reply But... My issue is not that I cannot get such a validation to work (...) (and yes, there are workarounds...) My problem is that I prefer to have validations in the domainmodel when this is possible (and it is possible / desirable when you want to have some validations applied system-wide). In such cases the best place to put validations is in the domainmodel: then this is maintained on 1 place and applied to forms, webservices, microflow-actions etc... So thanks for the suggestion, but I still wonder if my problem is a bug or a wrong syntax usage...
asked
3 answers
4

I did a little research on your error and saw that it was based on the parsedatetime function of joda. On their site they state that they use the ISO8601 standard which is equal to yyyy-MM-dd or 2000-02-15 in your case. For more info please take a look at wikipedia

However, i would still recommend you to use microflows over validation rules. Also see my comment on your op ;]

answered
2

I would use a Regex for this. You can use the community commons module to test a regex in a microflow. What microflow did you use for the validation?

answered
2

I would suggest not to use the default validation rules as they are applied at all times and can sometimes be confusing, especially since they also trigger on refresh of you object.

Then create a custom save button that checks the following:

$inputObject/Date => parseDateTime('01-01-2000', 'dd-mm-yyyy')

If true then you continue to save if false then you stop and do nothing.

If you want to warn the user beforehand you set a onchange microflow that basically does the same check if true it does nothing if false you present the user with validation feedback and optionally clear the date.

answered