Hello,
at the moment I use for the issues task and epic the same workflow and in general I would like to create a epic every time I create an new task-issue so I can link the task-issue to the epic. That's I defined a postfunction on the create transition of the workflow with the follow groovy-script:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.apache.log4j.Logger
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
if (issue.issueType.name=="Task")
{
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.key)
log.debug("Task-Key: ${issue.key}")
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "[Rel Request]" )
.setDescription("test desc")
.setIssueTypeId("7")
.setPriorityId("4")
.setReporterId(issue.reporterId)
.addCustomFieldValue("customfield_10907", "Lorem ipsum")
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters)
IssueService.IssueResult createResult = issueService.create(user, createValidationResult)
log.debug("Epos-Key: ${createResult.getIssue().getKey()}")
}
and the code works fine except two things first (and that's the main-problem) I don't get the ID of new created issue back, so I don't have any option to link my task-issue to the new epic issue.
The second thing is I looks like it works when I use for the epic and the task-type different workflows but here is the problem that the user want to use for both types the same workflow.
Now I am hoping someone here can give me a hint what I am doing wrong, I am thanksful for every hint because I am a complete groovy noob the code above was created by guessing and try-and-error-programming.
best regards
Dan
Edit
At the Moment I am thinking this is a kind of recurse-problem but I don't get any further output when I set additional log-output before the if-statement
I tried your code in the scriptrunner console in my environment and it works just fine.
I did have to add setAssigneeId and put the customField id for my Epic Name field, but otherwise, it worked ok.
A strange thing, however, the console didn't pick up any log items after the issueService.create call. But the log outputs were visible in atlassian-jira.log file. So it's more about the log getting disconnected from the scriptrunner instance.
But I'm not sure what you mean about users wanting different workflows. The workflow is determined by your project's workflow scheme. You can only pick the project and issue type, the scheme will determine what workflow this goes with.
To assign the new task to the epic, you will need to populate the epic link field on your task.
//Epic Link = 12205
def taskInputParam = issueService.newIssueInputParameters()
taskInputParam.addCustomFieldValue('customfield_12205', createResult.issue.key)
def updateValidationResult = issueService.validateUpdate(user, issue.id, taskInputParam)
updateValidationResult.errorCollection
def updateResult = issueService.update(user, updateValidationResult)
One thing to keep in mind ... is that I don't think that this will have re-indexed the epic ... so searching for issueFunction in issuesInEpic("key = newEpicKey") fails to return any issues.
So you may want to add an extra step to re-index the epic after adding it to the task's epic link.
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(createdResult.issue)
ImportUtils.setIndexIssues(wasIndexing)
You will need these import to re-index:
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
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.