Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

When is a Jira Issue assigned an issue key?

RJ Dlobik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 28, 2020

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!

2 answers

0 votes
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2020

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.

0 votes
Andrew Laden
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2020

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)

Suhyun Kang December 28, 2020

Thanks!

Suggest an answer

Log in or Sign up to answer