Hello there,
i am facing an issue with a post function.
When i want to close an issue, i get a transition screen.
In the screen i get a cloture date (custom field). I want to set this field by default with the date of the current day.
To reach my goal, i set a post function in my transition where i define my transition screen.
The post function triggered a custom script (describe below).
When i use the transition:
i) the field isn't set with the date of today
ii) when i want to save and move on to a close the issue i get an error according to the JAVA date library.
I dont get it, I use another similare script in the same WF and it's works well (triggered by postfunction too)
Here is my script:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.util.Date.*;
def Issue issue = issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfdatedefin = customFieldManager.getCustomFieldObject("customfield_10204")
Date Today = new Date()
cfdatedefin.setFormValue(Today.toString())
Do you have any information to help me on this point?
Hello there,
i finaly reach my goal.
I add a initialiser in a behavior.
I test my transitionname and if it is ok i set a date of today in my formfield.
Hope it's help someone.
Thank you for sharing it, Olivier!
Have a nice day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Olivier,
Actually, you don't need to use a Script to add the current date to your custom field.
You can use the post-function Update issue Custom Field and set the custom field value with the macro '%%CURRENT_DATETIME%%' or '%%CURRENT_DATE%%', which will be replaced by the date/time or only the date when you execute of the transition.
Please, let me know if this option helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Petterson,
Unfortunatly i didn"t have this post function. All i get is describ in the following picture.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Petter,
I used the above macro re '%%CURRENT_DATE%%' and am getting an "..illegal workflow operation." transition error when attempt the transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Philemon Nkafu
Can you please double-check if the field you are trying to set is a Date field instead of a Date and Time field?
If it is a Date and Time field, try to use '%%CURRENT_DATETIME%%'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Petter Gonçalves
I checked the CF and can reconfirm that it is a date picker field. Am working on Jira server v7.4. Could that be the problem i.e does the solution work only for cloud?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Petter, this works beautifully well
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Petterson,
Thanks for your reply!
At least my script is theoricly correct. I have performed a last check this morning and there is no behavior, no another post function, nothing than can get into conflict with my code.
As you said , i gonna ask the Adaptavist support.
Thanks for you time !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome, Olivier.
Please, let us know the feedback of Adaptavist.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello There,
i was thinking about something, does it is possible to set a default value in a transition screen ?
Olivier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Olivier,
I'm sorry to hear that you are facing difficulties to apply this functionality. In fact, the Script provided should be working for you.
About your last question, you can only set a Default value for a field in the creation screen of the issue, but not in the posterior transition screens.
There's a discussion about it here: Default value on custom field for a transition screen
Another option would be to use a system field (Due date, for example) instead of a custom field, so you would be able to use the post function Update Issue field.
If you would like to further troubleshoot your Groovy Script, I think that the Adaptavist support will be able to help you with this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
No one have any suggestion for setting a Date customfield with the date of today threw a post function script?
With only Scriptrunner ?
Olivier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Olivier,
Using ScriptRunner, you can try the solution mentioned by Vasiliy Zverev on the answer below:
How do I set a custom field with the current date/time in a post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Petterson,
based on your answer, i try this custom script added to a post funciton:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.util.Date.*;
// get current issue
Issue issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get today's date
Date today = new java.sql.Timestamp(new Date().getTime())
CustomField cfdatedefin = customFieldManager.getCustomFieldObject("customfield_10204")
issue.setCustomFieldValue(cfdatedefin, today)
and it is not working.
This is realy anoying to didn't get a simple behavior that pre default a custom field with a simple date.
I have to paid an add on for trying to do this, and finaly it is not possible or so ?
The more i try, the more i search the less i reach my point.
Atlassian really have to develop this basic functionnality in anative JIRA / JIRA SD imo.
Do you have any suggestion where i miss up ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Olivier,
Sorry, I didn't notice that you are using JIRA Server. Here's the plugin that provides the mentioned post function for JIRA Server:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Helloo,
thank for your feedback.
unfortunatly i can't get this add on (politic in firm about add-on is very clear) i have to handle it only with script runner ....
Olivier
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.