Forums

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

Create custom event which triggers listener for fast track transition

Sylvain Reissier June 16, 2020

Hello everybody,

I am updating my company workflows. I have two projects, Customer Support and Logistics, with respective issue type and workflow. I would like that a transition from an issue in the Support workflow create an issue in the Logistics workflow AND transition it to the correct status.

For example :

  1. issue type Service S-0001: transition "part repaired"
  2. Postfunction Clone issue -> Create a logistic issue L-0001 linked to S-0001
  3. Postfunction Create Custom event : E-0001
  4. In the logistic project : Listener sees E-0001 from S-0001 -> Fast track S-0001 to status "Ship the part"

Cloning the issue is fine, with Scriptrunner has this function exists and does not need mastering scripting. However, I do not know how to create this event as all the documentation I found on custom events are related to emails or other irrelevant updates.

 

Do you have suggestion on how to articulate this mechanism?

1 answer

0 votes
Mathis Hellensberg
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.
June 16, 2020

So you need a post-function that creates a linked issue in another project, and fast-tracks the created issue to a selected status?

Sylvain Reissier June 16, 2020

Yes. I tried to do it in one step from the scriptrunner "Clone issue -> Additional issue action" table but could not make/find a functionnal script.

Mathis Hellensberg
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.
June 16, 2020

Give me a sec :)

Mathis Hellensberg
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.
June 16, 2020
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issueService = ComponentAccessor.issueService
def issueLinkService = ComponentAccessor.issueLinkManager
def userManager = ComponentAccessor.userManager
def user = userManager.getUserByName("admin")
def issueInputParameters = new issueInputParameters()
def createdIssue

// Create new issue.
issueInputParameters.setSummary("Something")
issueInputParameters.setProjectId(10001)
issueInputParameters.setIssueTypeId("10010")
//issueInputParameters.addCustomFieldValue("customfield_<id>", "Value") //If you wanna add custom field values.

def validationCreateResult = issueService.validateCreate(user, issueInputParameters)

if (validationResult.isValid()) {
    createdIssue = issueService.create(user, validationCreateResult)
} else {
    log.info("Something")
}

//Link created issue to parent.
def issueLinkType = 10003 //Id of the type of link ex. Relates, linked etc.
issueLinkManager.createIssueLink(createdIssue.id, issue.id, issueLinkType, 1, user)

//Transition created issue.
def actionId = 101 //Change this to whatever workflow transition Id you wanna use.

def validationTransistionResult = issueService.validateTransition(user, createdIssue.id, actionId, new issueInputParameters())

if (validationTransistionResult.isValid()) {
    issueService.transition(user, validationTransistionResult)
} else {
    log.info("Something")
Mathis Hellensberg
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.
June 16, 2020

Let me know if you have any questions or problems! :)

Sylvain Reissier June 17, 2020

When I run it in the Script console I am unable to resolve class issueInputParameter.

 

Also, as the creation and linking actions are already built in, it would be nice to only have a listener doing the transition or even in the script console from the "clone and link" function 

Mathis Hellensberg
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.
June 17, 2020

Sorry, my fault. This works in my script console :)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.link.IssueLinkService
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issueService = ComponentAccessor.issueService
def issueLinkManager = ComponentAccessor.issueLinkManager
def userManager = ComponentAccessor.userManager
def user = userManager.getUserByName("admin")
def issueInputParameters = issueService.newIssueInputParameters()
Issue createdIssue

// Create new issue.
issueInputParameters.setSummary("Something")
issueInputParameters.setProjectId(10200)
issueInputParameters.setIssueTypeId("10001")
//issueInputParameters.addCustomFieldValue("customfield_<id>", "Value") //If you wanna add custom field values.

def validationCreateResult = issueService.validateCreate(user, issueInputParameters)

if (validationCreateResult.isValid()) {
createdIssue = issueService.create(user, validationCreateResult).getIssue()
} else {
log.info("Something")
}

//Link created issue to parent.
def issueLinkType = 10003 //Id of the type of link ex. Relates, linked etc.
issueLinkManager.createIssueLink(createdIssue.id, issue.id, issueLinkType, 1, user)

//Transition created issue.
def actionId = 891 //Change this to whatever workflow transition Id you wanna use.

def validationTransistionResult = issueService.validateTransition(user, createdIssue.id, actionId, issueService.newIssueInputParameters())

if (validationTransistionResult.isValid()) {
issueService.transition(user, validationTransistionResult)
} else {
log.info("Something")
}
Mathis Hellensberg
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.
June 17, 2020

Sorry..

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.link.IssueLinkService
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issueService = ComponentAccessor.issueService
def issueLinkManager = ComponentAccessor.issueLinkManager
def userManager = ComponentAccessor.userManager
def user = userManager.getUserByName("admin")
def issueInputParameters = issueService.newIssueInputParameters()
Issue createdIssue

// Create new issue.
issueInputParameters.setSummary("Something")
issueInputParameters.setProjectId(10200)
issueInputParameters.setIssueTypeId("10001")
//issueInputParameters.addCustomFieldValue("customfield_<id>", "Value") //If you wanna add custom field values.

def validationCreateResult = issueService.validateCreate(user, issueInputParameters)

if (validationCreateResult.isValid()) {
createdIssue = issueService.create(user, validationCreateResult).getIssue()
} else {
log.info("Something")
}

//Link created issue to parent.
def issueLinkType = 10003 //Id of the type of link ex. Relates, linked etc.
issueLinkManager.createIssueLink(createdIssue.id, issue.id, issueLinkType, 1, user)

//Transition created issue.
def actionId = 891 //Change this to whatever workflow transition Id you wanna use.

def validationTransistionResult = issueService.validateTransition(user, createdIssue.id, actionId, issueService.newIssueInputParameters())

if (validationTransistionResult.isValid()) {
issueService.transition(user, validationTransistionResult)
} else {
log.info("Something")
}

Suggest an answer

Log in or Sign up to answer