script validator check dates

A script has to validates if start and end date are on the same day when part time absence is morning or afternoon.

Part time absence (radio buttons custom field)

Possible options: Morning, Afternoon, No

Start date and End date (both date custom fields)

(All are required.)

My condition atm:

(cfValues['Parttimeabsence'].value != "No")&&(cfValues['Startdate'].value!=cfValues['Enddate'].value)

But it doesn't work.

Any ideas?


2 answers

1 accepted

2 votes
Accepted answer

You should remove the .value from the date fields:

(cfValues['Parttimeabsence'].value != "No")&&(cfValues['Startdate'] !=cfValues['Enddate'])

Tried, didn't work

The type of the date fields is not datetime, but date right ? I've just tried the same condition and it works. You may try to debug it :

Type is Date picker, so yes, I think it will be Date.

Strange that you have to debug such an easy statement, but shall test it out.

I don't need anthing else except that line, do I?


cfValues is a map of names on values, why don't I always need the .value ?

And what's the difference between ' ' and " " ?

It's really easy statement and it works for me, so there is something at your side, that's why it's best to debug instead of wasting time to try anything else

Are you wanting to these two dates for equality? Ie you want to confirm that they're the same down to the millisecond?

If you want to check that they're the same day (with all the complexity that brings when you have multiple time zones) you have to compare the year and day of year from the Date object.

As well as logging try using assertions:

Atm I'm wasting time figuring out how to debug it.
Never used groovy, nor intelliJ before.
So I don't know how it works and what I must do.

(And i'm back complaining ...)

Time part is unimportant.
Users can only choose the date, so time part will be default.

What are the functions for those comparators?
Guess it wont be compareTo() or equals()?

Tried also add assert to the condition.
Should i have seen something special/happening?

PS: Sorry I'm so frustrated. Spent at least 4h searching for something and I hate it when something doesn't proceed...

I thought the time part of the date field will always be 00:00:00.0. And I ment to add some trace messages rather then really debugging through an IDE :)

Trace messages?

Some prints of the variables?

Yes. It's shown how to do that in the link I've sent.

See here the Temporary changing the log level section

and set com.onresolve.jira.groovy to DEBUG level

Then just use println cfValues['Parttimeabsence'].value etc... and check the log file for the traces.

secure/CreateIssueDetails.jspa [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: value for class: com.opensymphony.user.User

[InvalidInputException: [Error map: [{}]] [Error list: [[Start date is not equal to end date.]]]

Is something
looking for more

WTF is this now?
can't add

'log4j.appender.filelog=org.apache.log4j.RollingFileAppender = DEBUG, console, filelog = false '


'Please check if this file is openend in another program.'
Even when JIRA (server) was shutdown, I couldn't change the file.

So looked in the (old) jira log:

Cannot get property 'value' on null object


Strange, all my fields are all obligatory so they aren't null because no value was in it.

so cfValues['Parttimeabsence'] must be unexisting..
Spaces must be deleted out of the name and it isn't case sensitive?

Going to try it out with the CF-ID (cfValues[1000XX] ?).

In case you need the full error:



CF-ID (cfValues[1000XX]) has no effect.

Still doens't work.

As Boris said:

cfValues["First Date"] == cfValues["Second Date"]

worked fine for me. Although the object is a Date, the time portion is zeroed. (Ie a java.util.Date, which has a date and time).

So if this doesn't work, can you do:

assert cfValues["First Date"] == cfValues["Second Date"]

in the Admin->Condition Tester and paste up the output

Shouldn't that be

cfValues["FirstDate"] == cfValues["SecondDate"]
with no spaces?

No difference between same or different start and end dates,

issues gets both times created.

At least, it didn't give me an error because I wasn't using

cfValues['Parttimeabsence'].value != "No" .

Condition tester under which tab?


with assert:

2014-04-17 09:26:35,573 http-8080-4 ERROR test2 566x626x1 1ohlw0 0:0:0:0:0:0:0:1 /secure/CreateIssueDetails.jspa [atlassian.jira.workflow.SimpleWorkflowManager] Error occurred while creating issue.

[InvalidInputException: [Error map: [{}]] [Error list: [[Start date is not equal to end date.]]]


Added some println's:

println cfValues["Startdate"]
println cfValues["Enddate"]





Searching through the log file:

java.lang.NoClassDefFoundError: com/atlassian/jira/datetime/DateTimeFormatter

Maybe this is why i get NPE's??

> cfValues["FirstDate"] == cfValues["SecondDate"]

> with no spaces?

It depends what your CFs are called. Mine are called "First Date". If yours really are called Startdate and not "Start Date" then use that. If there are spaces in the name then they are significant.

Sounds like this is the issue.

With the assert you need to test it in the previewer as I said.

Huhn, I read at the site of groovy that spaces should be deleted ...

Previewer is where located? :s

OH GD, it really were the spaces. ><

I'm so happy it's finally fixed! :D


You made my day!

Watch for "evil" spaces next time :)))


In some of the JQL functions you remove spaces, to avoid multiple quoting problems. Maybe you read it there. If you find the docn that you saw let me know and I will double-check.

F r o m n o w o n I w i l l t y p e e v e r y t h i n g w i t h s p a c e s , j u s t i n c a s e . : P

Y e p i t w a s

Scripted JQL Functions With Comments

> 100") Custom field names are likely to have spaces, which can't be parsed. If so, remove thespaces. It's not case-sensitive but use camel-case for maximum readability. If your field…

E D I T :

O h I f o r g o t t h e s p a c e s

E D I T 2 :

F o r g o t t h e s p a c e s i n E D I T


My function doesn't work :s

I want that:

Part time absence | Start & End date | create?

Morning or Afternoon | Different | N

Morning or Afternoon | Same | Y

No | Different | Y

No | Same | Y

The condition is the condition to fire the error or to create the issue? :s

I think it's the condtion to create the issue, so:
(cfValues['Part time absence'].value == "No")||((cfValues['Part time absence'].value != "No")&&(cfValues['Start date']==cfValues['End date']))


!(cfValues['Part time absence'].value != "No" && cfValues['Start date']!=cfValues['End date'])

The issue should only not be created when part time absence is Morning or Afternoon AND start date isn't equal to End date.

But when part time absence is no and dates aren't equal, I get the error (however it should be ok)

cfValues['Part time absence'].value!="No" is always true :s
nvm: figured it out myself, correct statement:

!(cfValues['Start date']!=cfValues['End date']&&
!(cfValues['Part time absence'].equals("No")))

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,095 views 4 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you