create a workflow programatically?

I want to create a workflow, a workflowscheme and associate it to a project programatically.

Any code examples to help get me started?

2 answers

This widget could not be displayed.

JIRA saves a workflow as XML. If you already have your workflow in the correct XML format, then creating the workflow is quite easy:

WorkflowDescriptor myWorkflowDescriptor = WorkflowUtil.convertXMLtoWorkflowDescriptor(myWorkflowAsXml));
JiraWorkflow myWorkflow = new ConfigurableJiraWorkflow(myWorkflowName, myWorkflowDescriptor, workflowManager);
workflowManager.createWorkflow(anAdminUser, myWorkflow);

Otherwise, creating the Workflow could be cumbersome. It depends how complex you Workflow is.

Creating a WorkflowScheme:

Scheme scheme = workflowSchemeManager.createSchemeObject(myWorkflowSchemeName, myWorkflowSchemeDescription);
AssignableWorkflowScheme myWorkflowScheme = workflowSchemeManager.getWorkflowSchemeObj(scheme.getName()); // necessary intermediate step
AssignableWorkflowScheme.Builder myWorkflowSchemeBuilder = myWorkflowScheme.builder();

Assigning Workflows to the Scheme:

// default (all IssueTypes)
myWorkflowSchemeBuilder.setDefaultWorkflow(myWorkflow.getName());
// ... or only for a specific IssueType
myWorkflowSchemeBuilder.setMapping(issueType.getId(), myWorkflow.getName());

workflowSchemeManager.updateWorkflowScheme(myWorkflowSchemeBuilder.build());

Associate Scheme to Project:

workflowSchemeManager.addSchemeToProject(project, workflowSchemeManager.getSchemeObject(myWorkflowScheme.getId()));

Does this help?

I got it working but having some minor issues:

1. I create the workflow scheme

2. for every custom issue type of mine:

2a. i create the workflow for that issue type

2b. using myWorkflowSchemeBuilder.setMapping I associate the issuetype with the workflow

2c. I update the scheme: workflowSchemeManager.updateWorkflowScheme

3. outside of my for loop - I associate it to the project

workflowSchemeManager.addSchemeToProject(project, workflowSchemeManager.getSchemeObject(myWorkflowScheme.getId()));

The issue is that on the workflow page, my newly created workflows are listed as INACTIVE; however my workflow scheme is listed as ACTIVE and the association between the issue type and the newly created workflow looks right. What am i missing?

hello John , could you please share your code? 

This widget could not be displayed.

John,

Will you be able to share the code of what you achieved?

I'm looking for creating custom workflow along with screen transistions.

Thanks in advance

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in Canada

AUG Lunch Roundtable - August 13 - Highlights

Thanks to everyone who came out today for the lunch AUG - we had some great food and discussion (and ice cream sandwiches to fend off the heat!) The welcome and fun fact was great as well, what an aw...

30 views 1 3
View post

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