I have a workflow where on one of the transitions we need to check two date fields and either allow the transition or deny it.
we need this type of comparision:
"My custom field/future date" > CurrentDate()/today's date
So therefore, If the future date is larger than today's then allow transition, if it is not then give an error?
Is there anyway to achieve this? Script runner perhaps?
You can install the Script Runner plugin and add a validator to the transition you've mentioned with the following settings:
Validator type: Script validator
Date now = new Date() Date cfDate = new Date(cfValues['DateFieldA'].getTime()) new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
Replace DateFieldA with your Date Picker custom field's name.
*updated to reflect the comments of this answer.
Ah, my bad! The plugin is the Script Runner plugin: https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner
But yes, that's the plugin I used in conjunction with the script. I've updated my answer above to the correct plugin. Thanks for pointing that out!
The <=0 is a comparison operator that is similar to Java's. I'll break down the code line for you:
In short, if the current date is earlier than the date set in the cutom field, this script will return true; hence allowing the transition to proceed.
Excellent I see, However i am now getting this error when i try start progress
Could not load FunctionProvider class
It seems that you have tried to perform an illegal workflow operation.
If you think this message is wrong, please contact your JIRA administrators.
I'm and using the feature the produce periodic tasks, so by using the script runner's escaltion service i can bring the task into an active status by running the JQL "My custom field/future date" = StartOfDay()
However we need to be sure people don't set it to a later day when setting "My custom field/future date", but for some reason am getting this error? can you advise?
Ok, so your custom field's name is "My custom field/future date", yea? Also, it's a Date Picker type field?
When you try to add the script, did you choose the Script Validator option:
And then choose Simple scripted validator:
And finally add the script mentioned above in the Condition code box:
If all have been added, it should be like the following:
The above worked for me here. Let me know how this goes for you, mate!
It's called "Recurrence Date" and it is a Date Picker type field
This is my workflow:
As you can see, we use this to minpulate this as a task type for recurring tasks, and it's been working well. By using the Escalation sevice by script runner once "Recurrence Date = StartOfDay()" than it automatically transitions from "Deactive" into "Active", The Recurrence Date is set on completing the Task, thus transitioning it from "Active" to "Deactive", How ever at this point we need to make sure that the user cannot set the reccurence date older than the current date aka today's date.
He is my workflow step with your code:
So as you can see i want them to set the reccurence date when completing the issue and at this piont also not allowing them to insert a date older than today?
No no the escalation service isn't affecting your script, it seems it was another plugin i was using that i seemed to have disabled, but when transition ran is was still trying to find the function in the disabled plugin. After removing the function your script ran well.
Your script runs well with the escalation service! Thank you :)
This can be done, Write a workflow condition plugin which will help you to do this, look into this link, which may help you,
Hope this helps!
In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to have–in order to produce a reliable long-term roadmap. We're tur...
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!
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