Hello,
I am new to jira and been trying to get this script to run.
Iam working on a Server Installation on Version 7.5.2.
I am trying to achieve the following:
When a issue is created or updated, the dueDate of the issue will be set to the associated fixVersion releaseDate.
It tried a bit, but didn't get to far:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
def issue = event.issue
def project = issue.getProjectObject()
project.getVersions().each {
log.debug it
}
log.debug issue.getFixVersions()
I am stuck at now loading the Versions based on the name, that I got. To then retrieve the release date, if equal to the Issue.fixVersion.
I know the script needs to check if exactly one fixVersion is defined and only then it should run. But Iam far away from this step yet.
I hope somebody can help me with that. It would speedup our workenvironment immensely.
SOLVED
Thanks to @Tarun Sapra here is the complete solution:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
def issue = (MutableIssue)event.issue
def version = (Version)issue.getFixVersions().first()
if(version) {
def releaseDate = version.getReleaseDate()
if(releaseDate) {
issue.setDueDate(new java.sql.Timestamp(releaseDate.getTime()))
issueManager.updateIssue(event.getUser(), issue , EventDispatchOption.ISSUE_UPDATED, false)
}
}
Once you have the issue object you can try something like this
def version = (Version)issue.getFixVersions().first()
if(version) {
def releaseDate = version.getReleaseDate()
if(releaseDate) {
issue.setDueDate(new java.sql.Timestamp(releaseDate.getTime()))
}
}
API reference - https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/issue/MutableIssue.html
Here I take into account that the issue has only one fixVersion associated with it or the first one is taken into consideration if there are many values for fixVersion on an issue.
Also TimeStamp is of type java.sql and Date(releaseDate) is of type java.Util .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wow Thank you for the fast anwser.
I implemented your code:
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def issue = (MutableIssue)event.issue
def version = (Version)issue.getFixVersions().first()
if(version) {
def releaseDate = version.getReleaseDate()
if(releaseDate) {
issue.setDueDate(new java.sql.Timestamp(releaseDate.getTime()))
}
}
The Code is running and it doesnt but out any errors, but it although doesn't set the DueDate on the Issue.
Did I miss something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Marcus,
This code should work fine in the "post-function" of the create transition.
Where are you using the code?
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.
But where do you want to use it? In the *post-function* of create transition or in the *Listener* ??
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.
To update the issue in "Listener" you have to use the "issueManager"
please see code snippet here
basically add in the end and that should do the trick
issueManager.updateIssue(event.getUser(), issue , EventDispatchOption.ISSUE_UPDATED, false)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sir, I saw your script based on fixversion date due date is updated.
Similar related question i had raised in community but no responce can you please look into my question
Based on fixversion value subtask will be created please suggest me how to achieve this script
Thanks a lot
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline 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.