Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Script Runner - Create linked issues and conditions on automation

@Steven Behnke

Hello Steve...As you ask I've created the topic on Atlassian answers.

So, may be you can help me. As we know Service Desk is not mature and we have to create somme tools with allow to create correct issue linked with the ticket and to floww their transitions

Create the linked issue.

If you want to create an issue link in service desk you have to use their create linked issue dialog...but it is not operationnal...very limited.

So I asked to adaptavist support who told me that internally they don't use this "create linked dialog" because it's so limiting, instead they use with a behaviour that copies whatever fields we want from the linked issue.

And it works...but you can't change the project type or the issue type in the dialog box...So I had to create as many buttons as need in the menu "More" of the issue. Too bad. I've asked to the adaptavist support...I'm waiting their respond.

Automation and transition

My second problem is to be able to put a comment in the parent issue (Service Desk) and to transition it to resolve when the linked issue is closed. Unfortunatly the automation system in Service Desk doesn't they've created a bug for me (JSD-4357) witch will be fixed in the 3.3.0 version.

So I've decided to search how doing it...and I've created Adds a comment to linked issues when this issue is transitioned poste function in my workflow...It works but for all my project...I would like to put a comment in the linked issue only if this type is Service Desk


QUESTION 1 : According to you is it possible when a issue is transitionned to status closed :

  • to add a comment to linked issues, if these issues belong to a projet type or issue type ?
  • to transitione these linked issues to resolve, if these issues belong to a projet type or issue type ?

If you can help me will be great smile

Best regards, Olivier

8 answers

1 accepted

0 votes
Answer accepted
JamieA Rising Star Nov 10, 2016

> And it works...but you can't change the project type or the issue type in the dialog box...

We use a velocity context handler that chooses the right dev project for the support project. But if you have many different choices for the project, we can't really handle that, other than create the issue in the wrong project then move it.

We set up the "create issue" link using "raw xml module":

<web-item key='create-bug-for-ticket' name='ScriptRunner generated web item - create-bug-for-ticket' section='operations-operations' weight='1'>
  <label>Create Linked Bug</label>
  <condition class='examples/jsd/IsScriptRunnerSupportProject.groovy' />
  <context-provider class="examples/jsd/DevProjectContextProvider.groovy" />
  <link linkId='create-bug-for-ticket'>/secure/CreateIssue.jspa?pid=$devProjectId&issuetype=1</link>

You get most of that from running Preview on the "constrained create issue".

Then teh context-provider code is:

package examples.jsd

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.plugin.webfragment.contextproviders.AbstractJiraContextProvider
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
import groovy.util.logging.Log4j

class DevProjectContextProvider extends AbstractJiraContextProvider {

    ProjectManager projectManager = ComponentAccessor.getProjectManager()

    public static final Map<String,String> SUPPORT_TO_DEV = [
        "SRJSUP"   : "SRJIRA",
        "SRCONF"   : "SRCONFSUP",
        "SRBSUP"   : "SRBITB",

    Map getContextMap(ApplicationUser user, JiraHelper jiraHelper) {

        def project = jiraHelper.getProject()

        def devProjectId = null

        if (project) {
            def devProjectKey = SUPPORT_TO_DEV[project.key]
            if (devProjectKey) {
                devProjectId = projectManager.getProjectObjByKey(devProjectKey)?.id
            else {
                log.warn("Create linked issue applied to project we don't know about: ${project.key}")

        ["devProjectId": devProjectId]


<web-item key='create-bug-for-ticket' name='ScriptRunner generated web item - create-bug-for-ticket' section='operations-operations' weight='1'>  <label>Create Linked Bug</label>  <condition class='examples/jsd/IsScriptRunnerSupportProject.groovy' />  <styleClass>sr-create-bound-issue</styleClass>  <context-provider class="examples/jsd/DevProjectContextProvider.groovy" />  <link linkId='create-bug-for-ticket'>/secure/CreateIssue.jspa?pid=$devProjectId&amp;issuetype=1</link></web-item>

> .I would like to put a comment in the linked issue only if this type is Service Desk
That built-in script doesn't take a condition, but it should. The code is more or less:


Issue issue = params['issue'] as Issue
        String linkTypeStr = params[FIELD_LINK_TYPE] as String
        String commentTemplate = params[FIELD_COMMENT] as String
        String linkTypeId = ""
        String linkDirection = ""
        (linkTypeId, linkDirection) = linkTypeStr.split(/ /) as List

        IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()
        CommentManager commentManager = ComponentAccessor.getCommentManager()

        def currentUser = WorkflowUtils.getUser(params)

        List links = []
        if (linkDirection == CannedScriptUtils.OUTWARD_FIELD_NAME) {
            links = linkMgr.getOutwardLinks(
        else if (linkDirection == CannedScriptUtils.INWARD_FIELD_NAME) {
            links = linkMgr.getInwardLinks(

        links.each {IssueLink link -&gt;
            if (link.getLinkTypeId() == linkTypeId as Long) {
                Issue destIssue = linkDirection == CannedScriptUtils.OUTWARD_FIELD_NAME ? link.getDestinationObject() : link.getSourceObject()
                Writable template = WorkflowUtils.mergeTemplate(params, commentTemplate)
       ("Create comment on ${destIssue.key}")

                def userUtil = ComponentAccessor.getUserUtil()
                if (! currentUser) {
                    log.warn ("Cannot create a comment for anonymous user")
                def appUser = userUtil.getUserByName(currentUser.getName())
                commentManager.create(destIssue, appUser, template.toString(), true)

so you can just use that but add a condition.

Stupid question, but where/how do I add the "context-provider code"

You just need to put that into one of your script roots directories. By default, there's one in $JIRA_HOME/scripts. Make sure to put it in the appropriate packages based on the package declaration at the top. So, for the linked example, the directory would be $JIRA_HOME/scripts/examples/jsd/.

1 vote
Jack Brickey Community Leader Nov 04, 2016


I assume you are on server and not cloud. I know that on cloud this is possible via Automation as I do this today, or something very similar. In brief my solution is this.

Scenario: Product issue come in thru my IT helpdesk and I want to alert/track the product issue in JSW while maintaining the original JSD issue, linking the two.


  1. I clone the IT issue and move the clone to the product project in JSW, creating a clone link
  2. I have automation setup in JSD to resolve an issue if the associated linked issue is cloned adding a comment that aligns with the the resolution type of the linked issue (done, cannot reproduce, won't do, etc)
  3. As an extra, I also have a separate SLA for product issues such that when I move the JSD issue into a status that equates to 'waiting on dev' then the IT SLA pauses and the Product SLA starts.

I'm surprised that the server versions would not support this and it would be unfortunate.

0 votes

Oh wow! It looks like the @mention didn't work, I'm sorry I never found this. I was searching around and I was a little shocked to see my name at the top. I'm glad you got your answer.

0 votes
Jack Brickey Community Leader Nov 08, 2016


yes my automation only transitions a linked issue not create an issue. While I have not researched that specifically, I do not believe JSD Automation will meet that need. My agents manually create and move the linked issues.

@Jack Brickey

Hello Jack,

When I read your automation  I understand that your trigger is when the linked issue is transitionned, when its status is changed. I'm allright ?

According to you is it possible to triggerring the automation when the the linked issue is created ? Because this is I would like to do...

Thank you Jack !

It is almost what I've done but in the JSD server it doesn't work...the Atlassian support did a bug.

0 votes
Jack Brickey Community Leader Nov 07, 2016

image2016-11-7 9:50:59.png

Hello Jack.

Thank you for your answer. It helps me.

Do you have a capture or the details of your automation in JSD ?

Suggest an answer

Log in or Sign up to answer