Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can we retrieve transition Id from transition name?

Happy New Year to everyone :)

Could any one please guide me how to retrieve transition Id from transition name?
I want to transition a linked issue through groovy script from custom script post function:
Here is the current rough script:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.workflow.IssueWorkflowManager
import com.opensymphony.workflow.loader.ActionDescriptor
import com.atlassian.jira.workflow.edit.layout.display.TransitionOption
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import static P3_Constants.Status
import static P3_Constants.Transition

def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.issueService
IssueWorkflowManager issueWorkflowManager
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

def movedIssues = issueLinkManager.getOutwardLinks(issue.id)

def movedIssueObjects = movedIssues.findAll {
it.issueLinkType.name == 'ABC'
}.collect {
issueManager.getIssueObject(it.destinationId)
}

//def transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build()
TransitionOptions.Builder transitionOptionsBuilder = new TransitionOptions.Builder()
transitionOptionsBuilder.skipConditions().skipPermissions().skipValidators()
TransitionOptions transitionOptions = transitionOptionsBuilder.build ()

movedIssueObjects.each {
def outerIssue = issueManager.getIssueObject(it.toString())
log.error "outerIssue---"+outerIssue
def linkedIssue = outerIssue as Issue
log.error "linkedIssue--"+linkedIssue
if (outerIssue.status.getName() != Status.CLOSED.name) {

log.error "Transition.DISCARD.name---"+Transition.DISCARD.name
log.error "transitionOptions---"+transitionOptions

ActionDescriptor issueTransition = issueWorkflowManager.getAvailableActions(linkedIssue, transitionOptions, loggedInUser).find {it.name == Transition.DISCARD.name}
log.error "issueTransition.id--"+issueTransition.id
assert issueTransition != null : "Workflow Action ${Transition.DISCARD.name} not found"

issueInputParameters.setResolutionId("10015")
def transitionValidationResult = issueService.validateTransition(loggedInUser, outerIssue.id, issueTransition.id, issueInputParameters, transitionOptions)
if (transitionValidationResult.valid) {
def transitionResult = issueService.transition(loggedInUser, transitionValidationResult)
if (transitionResult.valid)
log.debug "Transitioned issue ${outerIssue} through action ${issueTransition.id}"
else
log.debug 'Transition result is not valid'
}
else
log.debug 'The transitionValidation is not valid'
}
}

 

Problem: It always gives a NullPointerException for method getAvailableActions()

 

Below are the logs:

2022-01-05 16:33:30,073 ERROR [runner.ScriptBindingsManager]: outerIssue---XYZ-362
2022-01-05 16:33:30,074 ERROR [runner.ScriptBindingsManager]: linkedIssue--XYZ-362
2022-01-05 16:33:30,074 ERROR [runner.ScriptBindingsManager]: Transition.DISCARD.name---Discard
2022-01-05 16:33:30,075 ERROR [runner.ScriptBindingsManager]: transitionOptions---com.atlassian.jira.workflow.TransitionOptions@310b87eb
2022-01-05 16:33:30,080 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue BUS-3784 for user 'swapnil'. View here: http://localhost:8080/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Workflow+for+Project+BUS&descriptorTab=postfunctions&workflowTransition=1&highlight=4
java.lang.NullPointerException: Cannot invoke method getAvailableActions() on null object
	at P3.Script486$_run_closure3.doCall(Script486.groovy:43)
	at P3.Script486.run(Script486.groovy:33)

2 answers

0 votes
John Funk Community Leader Jan 05, 2022

Hi Swapnil - you can get the transition ID by clicking on the Text link while on the workflow. 

0 votes
Pramodh M Community Leader Jan 05, 2022

Hi @SWAPNIL SRIVASTAV 

Use the below API to get the transition 

You need the Issue key as an input parameter to get the transitions associated with that issue and by filtering the Issue transition name you can get the ID

https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-getTransitions

Thanks,
Pramodh

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

👋 Looking for 15-20 volunteers to test Atlassian training content

Hi everyone! Are you interested in beta testing Atlassian University’s newest (unreleased!) training course? We’re looking for 15-20 volunteers to test our newest training course, Basic reporting...

759 views 24 28
Read article

Community Events

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

Events near you