How can I get the Issue in scope when using custom Post Function?

I've created the script below to transition related tickets. I tested it using Script Runner and by adding an issue as a string in .getIssueObject().

def issue = constantsManager.getIssueManager().getIssueObject('AM-1234')

How can I get/pass the current issue that is transitioning into the scope of the Post Function? New to Groovy/JAVA and JIRA. :)

// Transition script to transition an inWardLinked issue status when related link is approved 
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils

def constantsManager =  ComponentManager.getInstance()
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil)JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class )

def issue = constantsManager.getIssueManager().getIssueObject('AM-1234')
def issueLinkManager = constantsManager.getIssueLinkManager()
def relatedLinks = issueLinkManager.getInwardLinks(issue.id)

relatedLinks.each {issueLink ->
def linkedIssue = issueLink.getSourceObject()
// If related linktype is not in ABTEST project and it's status is "in design" transition status to approved
if (issueLink.issueLinkType.name == "Related" && linkedIssue.getProjectObject().getKey() != "ABTEST" && linkedIssue.getStatusObject().getName() == "In Design"){
        workflowTransitionUtil.setIssue(linkedIssue)
        workflowTransitionUtil.setAction(421) // design approved - see text view of workflow to get transition ids
        workflowTransitionUtil.progress()
}}

1 answer

0 vote

It's in the script binding, which means you just refer to it without declaring it. So just comment out your line 15 and it should work.

I removed line 15 and line 17 started to fail. So I then tested in Script Runner with line 17 set t0

def relatedLinks = issueLinkManager.getInwardLinks()

This run without error in Script Runner but did nothing when I ran the transistion Post Function. Any ideas?

That doesn't make any sense... the line you mention above is not valid. Can you add some logging...

Sorry for slow reply.. got torn away for a while. Error log is.

[onresolve.jira.groovy.GroovyCondition] Script condition failed on DWORK-2092: issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Related')
java.lang.Exception: Cannot find a script engine for extension: "contains('Related')", (make sure it's on the classpath).

Sounds like you are pasted this into the text box that is for putting in a path to a file. Can you attach a screenshot.

This error occurs when I transition the issue to the approved state and the post function runs. This isn't from running the Script Runner add-on. Is that what you were thinking?

This error occurs when I transition the issue to the approved state and the post function runs. This isn't from running the Script Runner add-on. Is that what you were thinking?

Yes, it is from the script runner plugin... can you upload a screenshot of the config page for the workflow function.

This is what I see when I run the script in the text box. http://screencast.com/t/jfx04kya2

I get the same error when running from file.

http://screencast.com/t/szBcIAjhaR2

These are different errors to what I get when I transition an issue.

But it needs to be set up as a post-function. The admin script console is just a REPL for testing or running one-time scripts.

You need to edit a workflow, add a post-function, script function, then put the path to the file there, then publish the workflow, then test by putting an issue through that transition.

The original error is from when I add it as a post-function and tested by transitioning an issue through the transition.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,189 views 13 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot