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:
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?
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)
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.
Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events