Add a status to a workflow programmatically...com.atlassian.jira.workflow.edit.WorkflowStatus bug?

Tim Thompson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 31, 2022

We are going through a conversion (of 1,000s of projects) from Simplified Workflow to Fixed Workflows. The challenge is we have one issue type where we want to maintain existing statuses that have been defined on the board.

Using scriptrunner, I can get the board & statuses. I can also copy the workflow to establish it with base/common statuses but what I need is for any board status not on the specific workflow, add it. 

  • workflowManager.getLinkedStatusObjects() works to get the statuses/objects but doesn't have any methods to add or update. 

The class com.atlassian.jira.workflow.edit.WorkflowStatuses has the method 

but any import does not recognize it and the 

  • @JiraAgileBean WorkflowStatuses WorkflowStatuses

results in an error wiping out the scriptrunner declaration. 

Looking at com.atlassian.jira.workflow.edit.WorkflowStatuses using

 

  • importcom.atlassian.jira.workflow.edit.WorkflowStatuses and
  • WorkflowStatuses.getProperties().toString()

yields:

)\n)\n\n, genericSignature0:null, annotation:false, interfaces:[], anonymousClass:false, enclosingMethod0:null, simpleName:WorkflowStatuses, name:com.atlassian.jira.workflow.edit.WorkflowStatuses, enclosingMethod:null, genericInterfaces:[], annotationType:null, declaredClasses0:[], genericSuperclass:null, enclosingMethodInfo:null, simpleBinaryName:null, enclosingClass:null, canonicalName:com.atlassian.jira.workflow.edit.WorkflowStatuses, componentType:null, typeParameters:[], typeName:com.atlassian.jira.workflow.edit.WorkflowStatuses, genericInfo:null, enumConstants:null, annotatedSuperclass:null, signers:null, declaringClass:null, declaredClasses:[], reflectionFactory:sun.reflect.ReflectionFactory@3951679c, package:package com.atlassian.jira.workflow.edit, synthetic:false]

which looks corrupted. 

Any ideas? Alternatives?

 

1 answer

0 votes
Tim Thompson June 1, 2023

Answering my own question, I am able to now add global statuses (all statuses -->) to a workflow. The key code elements are:

// libraries:
import com.atlassian.jira.workflow.edit.WorkflowStatuses
import com.atlassian.jira.workflow.edit.WorkflowStatusesImpl

// code:
WorkflowStatusesImpl workflowStatusesImpl = ComponentAccessor.getComponent(WorkflowStatusesImpl)
workflowStatusesImpl.addStatusAndGlobalTransitionToWorkflow(ComponentAccessor.getConstantsManager().getStatusByName("statusName"),"WorkflowName")

Challenge now is that it seems to require Jira administration access whereas I want to delegate to project admins. I trap the command (with try {...} / catch (ex) {...}) and no error is thrown. It just doesn't do it if you are not a Jira administrator. 

Can add a status via the UI, so I'm sure it can be done. 

Suggest an answer

Log in or Sign up to answer