Create a transition in a workflow with scriptrunner

Hi !

As an exemple:
I’m starting from a workflow with only “To do”, “In progress”, “Done” and i want to add a status named “Analysis” and a transition from “Done” to “Analysis”.
I bases my code on this kb : https://community.developer.atlassian.com/t/create-workflow-through-java-api/4232
It’s very close to what i want to do but, for now, i’m focused on the transition.

Here’s my code :

def workflowManager = ComponentAccessor.workflowManager;
def constantManager = ComponentAccessor.constantsManager;
ActionDescriptor action = DescriptorFactory.getFactory().createActionDescriptor();
action.setName("To Analysis")
ResultDescriptor result = DescriptorFactory.getFactory().createResultDescriptor();

Status newStatus = constantManager.getStatusByName("Analyse");
Status oldStatus = constantManager.getStatusByName("Done");

JiraWorkflow workflow =  workflowManager.getWorkflow("MyWorkflow");

result.setStep(workflow.getLinkedStep(newStatus).id);
result.setOldStatus("Done");
result.setStatus("Analyse");

action.setParent(workflow.getLinkedStep(oldStatus));
action.setUnconditionalResult(result)

workflow.getLinkedStep(oldStatus).getActions().add(action)

The result is a totally unexpected.
Actually i have my transition between “Analysis” and “Done” but it had no name. I tried to use :

ActionDescriptor transition = new ActionDescriptor().setName();

With no success.

Besides the most incredible things is that i cannot access to my workflow anymore through the project settings or through admin > issue > workflow. I can only saw it from “Display workflow” in the issues of the project.
When i try to access from settings (project or admin) i get a 404 or a 500 error.

How can i have access to that workflow again ? (besides i can’t delete it either)
How can i do a pretty transition that doesn’t ruin my workflow ? I would also like to know if it’s possible to do one transition that like all statuses of the workflow to one, in one line of code.

Regards,

Laurent

Hi,

Honestly i’m a bit lost here…
Can someone explain me why nobody is answering? Did i miss something in the process of posting something on the community ? Did i lack courtesy ?
Those are honest questions…

I don’t think that my question is that difficult to anwser. (i’m sure there are people that know how to make a transition with code…), so i’m completly lost as why is nobody answering…

I hope someone can guide me !

Regards,

Laurent

This is a community. People answer as they have time and if they have the knowledge. If they don’t answer, then it would because the right knowledge hasn’t read your question and responded. Atlassian Answers has a more active ScriptRunner community: Most of the individuals in this community are add-on developers.
I certainly haven’t programatically added a transition to a workflow so I’m not able to answer you either.

1 Like

Hi,

Thank you for your answer, i may try to go to atlassian Answers then.
Since it’s the only answer and it somehow point me to a solution, i’ll count it as a solution.

Regards,

Laurent