Create WorkFlow Programmatically

FhatuN April 10, 2014

Hi guys,

In Jira workflow how do link status/steps to a transition?

What i have now:

- created work flow

- I created the step

Workflow.createWorkflowStep("Awaiting Approval", steps_id);

- createtd the status
Workflow.createWorkflowStatus("Awaiting Approval", "status for awaiting approval", this.statusManager);

- create transition

Workflow.createWorkflowTransition("InProgress_to_awaiting_approval", transition_id);


So now how do you link the steps to each other using transition

E.g A -- > B --> C


6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
FhatuN April 16, 2014

Hi Guys,

I found a much easier way to do the custom work flow for you plugin.

1. Create a workflow in jira

2. Save it as .jwb file

3. Copy it into your plugin

4. create .json script

5 And hook the .jwb file to your plugin

{
    "issue-type-scheme":
    {
        "name": "my.project.template.issuetype.scheme.name",
        "description": "my.project.template.issuetype.scheme.description",
        "issue-types": [
            {
                "key": "issueType1",
                "name": "issue type",
                "description": "A  has been made, which has yet to be developed.",
                "icon": "/images/icons/newfeature.png",
                "workflow": "wf2"
            }
        ]
    },
    "workflow-scheme":
    {
        "name": "my.project.template.workflow.scheme.name",
        "description": "Workflow scheme used by the  Workflow",
        "default-workflow": "wf2",
        "workflows": [
            {
                "key": "wf2",
                "name": "my.project.template.workflow.wf2.name",
                "workflow-bundle": "/wfb/Workflow.jwb"
            }
        ]
    }
}

Nidzhat Amrastanov November 25, 2014

And what should I do with this json?

Like Morchid Zakaria likes this
0 votes
Vikash Kumar
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.
September 8, 2014

Hi, 

After converting xml to descriptor we get WorkflowDescriptor. Using below code I am able to add the status which solved the problem of creating workflow and associating statuses with this.

workflowDescriptor = WorkflowUtil.convertXMLtoWorkflowDescriptor(myWorkflow);
                
                List<StepDescriptor> stepDescriptor = workflowDescriptor.getSteps();
                for(StepDescriptor sd: stepDescriptor) {
                    Status status = statusManager.createStatus(sd.getName(), sd.getName(), "/images/icons/statuses/xyz.png");
                    Map newStatus = new HashMap();
                    newStatus.put("jira.status.id", status.getId());
                    sd.setMetaAttributes(newStatus);
                }
 
Similarly we can add the screens as well.
 
Thanks,
Vikash
0 votes
Viktor Dlouhý
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.
August 25, 2014

I was trying to create workflows programatically, but then I found out, how complicated the structure is. So basically the easiest approach is to use already generated workflow and save it as XML, then using following code to import it. Jira-Core dependency is necessary.

WorkflowDescriptor wf = WorkflowUtil.convertXMLtoWorkflowDescriptor(xml);
JiraWorkflow w = new ConfigurableJiraWorkflow("JRMP Default Workflow", wf, ComponentAccessor.getWorkflowManager());
ApplicationUser user = getJiraServiceContext().getLoggedInApplicationUser();
if(ComponentAccessor.getWorkflowManager().workflowExists(w.getName())){
	ComponentAccessor.getWorkflowManager().updateWorkflow(user, w);
}else{
	ComponentAccessor.getWorkflowManager().createWorkflow(user, w);
}

Otherwise you can use DescriptorFactory and try to fill the data yourself....

WorkflowDescriptor wf = DescriptorFactory.getFactory().createWorkflowDescriptor();

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2014

Hi Fhatu,

please take a look to WOrkflowManager API https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/workflow/WorkflowManager.html

All you need can be retrieved there.

Regards,

Fabio

Uday Kumar May 28, 2014

Hi Fabio,

The API you are referring to doesn't have details on how to associate status/ transistion. Mostly the methods are getXXXX()

Do you know where we can we achieve the above?

Regards

Uday

FhatuN May 29, 2014

Im using the same API do edit the transition but it does not work

String workFlowName = newProject.getKey() + ": Quote Workflow";
        
        JiraWorkflow quoteWorkFlow = ComponentAccessor.getWorkflowManager().getWorkflow(workFlowName);
                
        Collection<ActionDescriptor> allTransition  = quoteWorkFlow.getAllActions();
        String transitionName = "Awaiting Client Feedback";
        String screenName = QuoteConstants.QUOTE_CLIENTFEEDBACK_SCREEN;
        
        for(ActionDescriptor transition : allTransition){
            if(transitionName.equals(transition.getName())){
                transition.setView(screenName);
                ComponentAccessor.getWorkflowManager().updateWorkflow(ComponentAccessor.getWorkflowManager().getWorkflow(workFlowName).getUpdateAuthor(), quoteWorkFlow);
            }
        }

Uday Kumar May 29, 2014

Hi Fhatu,

Thanks for the API. We will try and let you know if we have any success.

Regards

Uday

0 votes
FhatuN April 10, 2014

Cool will check it out...

0 votes
Boris Georgiev _Appfire_
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.
April 10, 2014

Please give more "complete" code example - what is this Workflow class ? Whare are you executing this code ? From a plugin ? or this is REST api ?

FhatuN April 10, 2014

From a plugin

Boris Georgiev _Appfire_
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.
April 10, 2014

Look at the com.opensymphony.workflow.loader.WorkflowDescriptor API

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events