You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hello all,
I am trying to compare the Start Date/time Custom field of a Change Request ticket type with the current system date/time. I want to ensure that if the CR is NOT an "EMERGENCY" change type, the Start Date/Time must be in the future.
Emergency CR tickets are allowed to be created after the actual work is completed.
I have the following Validator script on the Create transition:
Date currentdatetime = new java.sql.Timestamp(new Date().getTime())
log.warn ("??? - currentdatetime = " + currentdatetime)
log.warn ("??? - Change type = " + cfValues['Change type'])
log.warn ("??? - Planned Start Date = " + cfValues['Planned Start Date'])
if (cfValues['Change type'] != 'Emergency'){ log.warn ("Change type is NOT Emergency")
if (cfValues['Planned Start Date'] != null && cfValues['Planned End Date'] != null) { log.warn ("start and end dates are filled in")
if (cfValues['Planned Start Date'] < currentdatetime ) { log.warn ("Start Date is EARLIER than now")
return false
} else {log.warn ("??? - Start date is NOT before today")
return true }
}
} else { return true}
This works just fine when the change type is NOT Emergency type. however, it is not working as expected when the Change Type (Custom field) is equal to Emergency.
The output of the script is as follows:
2020-02-12 04:23:37,821 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - currentdatetime = 2020-02-12 04:23:37.821 2020-02-12 04:23:37,822 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - Change type = Emergency 2020-02-12 04:23:37,822 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - Planned Start Date = 2020-02-10 04:23:00.0 2020-02-12 04:23:37,822 WARN [workflow.AbstractScriptWorkflowFunction]: Change type is NOT Emergency 2020-02-12 04:23:37,823 WARN [workflow.AbstractScriptWorkflowFunction]: start and end dates are filled in 2020-02-12 04:23:37,823 WARN [workflow.AbstractScriptWorkflowFunction
I have a feeling it's something really simple, but I just can't figure it out.
Any and all answers/help is appreciated as always.
Hi @Ashvin Patel ,
is there a line of log missing ? I cannot see the result of the date comparison. Anyway you could also try (even though it should be equivalent) :
if (cfValues['Planned Start Date'].compareTo(currentdatetime) < 0){ ...
There was nothing after that last entry in the log file. I have tried your suggestion for the compare and it is still not working.
I think the issue is above this date comparison with the very first if statement:
if (cfValues['Change type'] != 'Emergency'){ log.warn ("Change type is NOT Emergency")
This comparison seems to evaluate as True, every time, even though in the logs, it clearly shows that the Change Type field value is Emergency:
2020-02-17 18:49:06,053 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - currentdatetime = 2020-02-17 18:49:06.053 2020-02-17 18:49:06,054 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - Change type = Emergency 2020-02-17 18:49:06,054 WARN [workflow.AbstractScriptWorkflowFunction]: ??? - Planned Start Date = 2020-02-03 18:46:00.0 2020-02-17 18:49:06,055 WARN [workflow.AbstractScriptWorkflowFunction]: Change type is NOT Emergency 2020-02-17 18:49:06,055 WARN [workflow.AbstractScriptWorkflowFunction]: start and end dates are filled in 2020-02-17 18:49:06,056 WARN [workflow.AbstractScriptWorkflowFunction]: Start Date is EARLIER than now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the issue is only when Change type value is Emergency, then your first if is probably not working since logs display
log.warn ("Change type is NOT Emergency")
Could you try adding this log
if (cfValues['Change type'] == 'Emergency'){
log.warn("Change type is Emergency")
}
Before the other if, and try to trigger the script when Change type value is Emergency ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Issue resolved. The problem was that I was not converting the single-select Drop-down selected value to a String before attempting to compare that value to another string.
I changed :
if (cfValues['Change type'] != 'Emergency'){
to:
if (cfValues['Change type'].toString() != 'Emergency'){
and that resolved the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or does it work ? :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed list (and checkbox) fields will need to be converted to string first for comparison. Anyway if you are satisfied with the resolution please mark the question as answered as it will help others in the future. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.