Hi,
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?
Thanks,
Warren
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
Script:
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.
Would this same script you have provided work in the script-runner by Jamie Echlin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What does the <= 0 stand for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, can you show what are your post functions for the Start Progress transition?
Also, it would be cool if you can let me know:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nothing on the Start Progress tranition, just the default post-functions.
Thanks, Hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem, Warren! Glad that it works now. :)
But it is indeed a strange thing that a script runner for the escalation is affecting this script. So, does this mean that both scripts are working well?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok Seems like it's working, THANK YOU JUSTIN SO VERY MUCH for all your help! I think there was another function that was causing the problem, but it seems your code is working well! Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I see. Glad that you got that part sorted out, mate! :D
You're welcome yet again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira Suite Utilities may help you:
https://jsutil.atlassian.net/wiki/display/JSUTIL/JIRA+Suite+Utilities+Workflow+Validators
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex, I did try this approach, however it doesn't support a custom field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This can be done, Write a workflow condition plugin which will help you to do this, look into this link, which may help you,
http://www.j-tricks.com/1/post/2010/08/workflow-condition.html
Hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nitram, This option looks very time consuming and may be a bit difficult?
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.