Any scripts available to transition through workflow for updating issue to any status

Reshmi Raveendran March 4, 2021

Hi,

I am trying to change status of an issue programmatically. since there are no direct transition for some statuses, i have to transition through all available transitions from the initial status. This is bit tricky(similar to travelling sales person algorithm). Trying to find some optimal solution for this.

I could see that below code is been used in Jira CSV importer plugin. I tried it but doesn't help if there is no direct transition available to my desired target status.

JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issueResult.getIssue());
StepDescriptor linkedStep = workflow.getLinkedStep(status);
 Collection wfCurrentStepCollection = CoreFactory.getGenericDelegator().findByAnd("OSCurrentStep",
 EasyMap.build("entryId", issueResult.getIssue().getLong("workflowId")));
 if ((wfCurrentStepCollection != null) && (!wfCurrentStepCollection.isEmpty())) {
 GenericValue wfCurrentStep = (GenericValue) wfCurrentStepCollection.iterator().next();
 if (linkedStep != null) {
 wfCurrentStep.set("stepId", Integer.valueOf(linkedStep.getId()));
 wfCurrentStep.store();
 }
 }
 issueResult.getIssue().setStatusId(request.getStatusId());
 issueResult.getIssue().store();

 

besides, some of the functions are deprecated here. 

eg: CoreFactory.getGenericDelegator() and issueResult.getIssue().store()

Any help would be much appreciated!

Thanks.

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2021

You must not just "set" the status.  That is only appropriate when creating new issues, it does not work for existing ones.

You are going to have to tackle your travelling salesman problem and work out an optimal route through the workflow to your desired point and issue a number of transitions to get there.

Fortunately, in this case, you don't have the travelling salesmen problem.   You're not actually trying to traverse all points, you probably want the shortest route, so Dijkstra's algorithm can be used (and is simplified because the length of each trip is 1)

Reshmi Raveendran March 8, 2021

Thanks a lot. i will try to look at Dijkstra's for updating status.

This might be a complex task as i am looking at updating status of a bunch of issues in the range 3k-5k. 

Still curious to know if Jira native CSV Importer Plugin is also using the same algorithm. The Atlassian documentation  available for this is only till Jira 7.x version. Mine runs in 8.x

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 9, 2021

CSV imports create issues, so they can set the status.

Suggest an answer

Log in or Sign up to answer