WorkflowManager.removeStep does not work if "All statuses can transition to ..."

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!
November 1, 2022

Attempting an alternate solution to my post here: https://community.atlassian.com/t5/Jira-questions/Add-a-status-to-a-workflow-programmatically-com-atlassian-jira/qaq-p/2178063

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.

In my other post I describe the issue with attempting to "add" a status to a workflow (using com.atlassian.jira.workflow.edit.WorkflowStatuses). Alternatively, I have tried taking a copy of the original simplified workflow with all the statuses and then deleting any steps related to statuses no longer necessary.

WHAT WORKS: 

Using ProjectRapidViewService.findRapidViewsByProject I retrieve all the boards for the project. From there I create a list of statuses to keep. I then use ComponentAccessor.workflowManager.copyWorkflow to create a copy of the simplified workflow.

  1. I have tried WorkflowManager getLinkedStatusObjects to get all the statuses and for the ones to remove getLinkedStep(thisSTATUS) to get the StepDescriptor.
  2. Alternatively I also have tried WorkflowManager getAllActions() to loop through actions and getStepsForTransition and for matching step status getting the StepDescriptor

WHAT DOESN'T WORK:

In both cases, with a valid StepDescriptor the removeStep(StepDescriptor) fails with the message

  • "message":"Cannot remove step - it is a destination step of at least one transition."

The documentation indicates it should reply with a boolean (true if the remove was successful) but when it fails it stops execution and throws this error.

How can I remove the step and/or status from the workflow in the case of ?

1 answer

0 votes
Nic Brough -Adaptavist-
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.
November 1, 2022

Yes, that's correct, you can not remove a step that has one or more transitions pointed to it.  You can't break the transition by leaving it hanging.

You need to change the end step of every incoming transition or delete the transitions before you can remove the step (bear in mind that includes "All" transitions).

The Boolean result you are seeing is because a Boolean statement can only be True, False or null/cannot-an-answer by definition.  Obviously, the null will happen when the statement is nonsense (Is the colour of this thing a clock?), but the way the code works is not "is it yes or no?", it is "is it true?  If it is, return true, otherwise return anything you want, because it's not true, so it must be false.

Suggest an answer

Log in or Sign up to answer