Script Runner - Create linked issues and conditions on automation

Olivier November 4, 2016

@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 https://scriptrunner.adaptavist.com/latest/jira/fragments/CreateConstrainedIssue.html 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 work...so 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 Steven...it will be great smile

Best regards, Olivier

8 answers

1 accepted

0 votes
Answer accepted
JamieA
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.
November 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' />
  <styleClass>sr-create-bound-issue</styleClass>
  <context-provider class="examples/jsd/DevProjectContextProvider.groovy" />
  <link linkId='create-bug-for-ticket'>/secure/CreateIssue.jspa?pid=$devProjectId&issuetype=1</link>
</web-item>

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

@Log4j
class DevProjectContextProvider extends AbstractJiraContextProvider {

    ProjectManager projectManager = ComponentAccessor.getProjectManager()

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

    @Override
    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(issue.id)
        }
        else if (linkDirection == CannedScriptUtils.INWARD_FIELD_NAME) {
            links = linkMgr.getInwardLinks(issue.id)
        }

        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)
                log.info ("Create comment on ${destIssue.key}")

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

so you can just use that but add a condition.

Martina Riedel
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.
March 2, 2017

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

Jonny Carter
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.
March 3, 2017

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 4, 2016

Olivier,

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.

Solution:

  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
Steven F Behnke
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.
April 12, 2017

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2016

Oliver,

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.

0 votes
Olivier November 7, 2016

@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...

0 votes
Olivier November 7, 2016

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2016

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

0 votes
Olivier November 6, 2016

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