How do I get the issue workflow name

Hi,

I have already a behavior set-up to make some specific fields mandatory or not depending on the resolution value from the resolve screen.

I want to elaborate the behavior script a bit and add an option that will not make a field mandatory if the project is using a specific workflow.

How can i get the workflow name in the script?

Thanks

 

3 answers

1 accepted

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.issue.Issue;
 
WorkflowManager workflowManager = ComponentManager.getInstance().getWorkflowManager();
 
JiraWorkflow workflow = workflowManager.getWorkflow(issue);
String workflowName = workflow.getName();

This assumes there is a standard issue object, such as in a validator or condition; if not you'll have to create the issue explicitly.

Hi Haiducu

In the behaviour script try this

import com.atlassian.jira.component.ComponentAccessor
def context = getIssueContext()
def projectId = context.getProjectId()
def issueTypeId = context.getIssueTypeId()
def workflowManager = ComponentAccessor.getWorkflowManager()
// use the String workflowName as you wish 
def workflowName = workflowManager.getWorkflow(projectId, issueTypeId).getName()
log.debug("Workflow name ${workflowName}")

Using the getIssueContext() you get an issueContext and from the workflowManager you can get a JiraWorkflow using the projectId and the issueTypeId.

Hope that helps.

 

Thank you for your answers. Both of them works. I am using the 1st one since I found it more easier to integrate in my existing code

If you use a condition in a worfklow transmission I would also use @Jeremy Gaudet solution, with a small modification, if I may, import com.atlassian.jira.component.ComponentAccessor worfklowManager = ComponentAccessor.getWorkflowManager() In case you wanted to use a [behaviour|https://scriptrunner.adaptavist.com/4.2.0.2/jira/behaviours-overview.html] Jeremy's script wouldn't work cause as he already correctly mentioned: "This assumes there is a standard issue object, such as in a validator or condition; if not you'll have to create the issue explicitly". Kind regards Thanos

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot