Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom Date field compared to SystemDate failing

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. 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry Community Leader Feb 13, 2020

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
Antoine Berry Community Leader Feb 19, 2020

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 ?

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'){


if (cfValues['Change type'].toString() != 'Emergency'){


and that resolved the issue.

Or does it work ? :D

yes, it works now :). Thank you for your time and assistance.

Antoine Berry Community Leader Feb 24, 2020

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. :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

808 views 17 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you