Forums

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

How Do I Get Available Transitions for Current Point in Workflow? - Script Runner

Dalectric
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.
May 10, 2018

I'm writing a Script Runner listener to automatically transition a linked issue and it's subtasks based on whether a component is added or removed to the base issue.

I see I can get all the available workflow actions using

jiraWorkflow.getAll AvailableActions("");

This lists all the available actions for the whole workflow.

I can also get all the available actions called a name (Reject in this case) with

jiraWorkflow.getActionsByName("Reject");

which can result in several items in my collection if the workflow has several actions(transitions) called Reject

I can iterate through these to find the one that matches the current workflow status and use that, but this seems messy and I'm not confident it's robust to different workflows which may have shared transitions (which give a parent status name of null) and individual transitions with the same name.

Is there a cleaner method to find the available actions for the current point in the workflow?

1 answer

1 accepted

2 votes
Answer accepted
Tuncay Senturk
Community Champion
May 10, 2018

Hello,

Below code might help. Bear in mind that I did not test it

WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
JiraWorkflow workflow = workflowManager.getWorkflow(issue);
workflow.getLinkedStep(status).getActions();
Dalectric
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.
May 11, 2018

Nice one, that worked a treat.

For the current status I've used it as follows

workflow.getLinkedStep(issue.getStatus()).getActions();
Like Ahmadi Islem likes this
Tuncay Senturk
Community Champion
May 11, 2018

I'm glad to hear that it works ;)

Kleber Fonseca
Contributor
July 30, 2018

Hi @Tuncay Senturk

 

Please

 

I'm trying too work with a code like this but...

how can i get the results ??

I've read Atlassatian OnLine Documentation and I saw that "getLinkedSetp" method returns 

com.opensymphony.workflow.loader.StepDescriptor

I would like to get the possible transitions (actions) basead on a issue state, just like the code above.

But, I have to fire a transition if I found a particular action. 

So, I must handle the Action Name (to search) and the Action ID (to fire) of the actions returned by "workflow.getLinkedStep( issue.getStatus()).getActions()

Is it possible?

Thanks in Advance

Kleber Fonseca
Contributor
July 30, 2018

@Tuncay Senturk

 

Forget it

I get it

import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor

JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(  _issue_  )

 

ActionDescriptor action

int actionID = 0
def actions = workflow.getLinkedStep( issuePai[0].getStatus() ).getActions().iterator()
while ( actions .hasNext() )
{
action= (ActionDescriptor)actions .next()

if( action.getName() == "my condition")
actionID= action.getId()
}

Like Ahmadi Islem likes this

Suggest an answer

Log in or Sign up to answer