I'm attempting to write a ScriptRunner Post Function on the "Created" transition for an issue, that will link the newly created issue to an existing Epic.
I'm running into issues though, as the issue key doesn't seem to be assigned yet during the Post Function of the "created" transition.
Here is the code:
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import configuration.JiraConfiguration
import org.apache.log4j.Logger
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def availableIssueLinkTypes = issueLinkTypeManager.issueLinkTypes
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkType = availableIssueLinkTypes.findByName("Depends")
issueLinkManager.createIssueLink("SEC-49" ,issue.getKey(), linkType.id, 1L, user)
And here is the error I'm receiving:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.link.DefaultIssueLinkManager.createIssueLink() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, null, Long, Long, com.atlassian.jira.user.DelegatingApplicationUser) values: [SEC-49, null, 10300, 1, 083673(083673)] Possible solutions: createIssueLink(java.lang.Long, java.lang.Long, java.lang.Long, java.lang.Long, com.atlassian.jira.user.ApplicationUser) at ValidateSecurityFields.run(ValidateSecurityFields.groovy:63)
Is there a better way to accomplish this other than a Post Function on the created transition?
Thanks!
Place your script in the last position of your post function. At this point, JIRA should already have assigned an issue key. Alternatively you can also use a script listener since this fires only after issue has been created and you can use the even.issue.getKey() to get your issue key.
Regards.
You could try automation with a trigger on the create event. (either with automation for jira, or creating your own listener.)
Also the order of your post functions is important. Make sure yours is at the bottom of the list. (you might need an extra re-index after it)
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.