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?
Thanks.
Bert
You should remove the .value from the date fields:
(cfValues['Parttimeabsence'].value != "No")&&(cfValues['Startdate'] !=cfValues['Enddate'])
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 :
https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner#ScriptRunner-Logging
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
EDIT1:
I don't need anthing else except that line, do I?
EDIT2:
cfValues is a map of names on values, why don't I always need the .value ?
And what's the difference between ' ' and " " ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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: https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-PowerAssertions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. It's shown how to do that in the link I've sent.
See here the Temporary changing the log level section
https://confluence.atlassian.com/display/JIRA/Logging+and+Profiling#LoggingandProfiling-loggingLogging
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
EDIT:
WTF is this now?
can't add
'log4j.appender.filelog=org.apache.log4j.RollingFileAppender
log4j.category.com.onresolve.jira.groovy = DEBUG, console, filelog
log4j.additivity.com.onresolve.jira.groovy = false '
in log4j.properties.
'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
NullPointerException
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:
ErrorLog.txt
EDIT2:
CF-ID (cfValues[1000XX
]) has no effect.
Still doens't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
EDIT:
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.]]]
EDIT2:
Added some println's:
println cfValues["Startdate"] println cfValues["Enddate"]
gives
null
null
EDIT3:
Searching through the log file:
java.lang.NoClassDefFoundError: com/atlassian/jira/datetime/DateTimeFormatter
Maybe this is why i get NPE's??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
THANK YOU ALL!! :)
You made my day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Watch for "evil" spaces next time :)))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
;-)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Y e p i t w a s
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
EDIT3:
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']))
OR
!(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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nvm: figured it out myself, correct statement:
!(cfValues['Start date']!=cfValues['End date']&&
!(cfValues['Part time absence'].equals("No")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.