It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Programatically Modify/Change/Update an issues status in Java

I've been looking for a solid Java example on how to programmatically make issue status transitions. I've seen: https://answers.atlassian.com/questions/6985/how-do-i-change-status-of-issue

... but it fails to comprehensively show all the steps necessary to transition the status of an issue. The section marked Pseudocode for jira 4.4 looks interesting, but I'm still without a good direction?

Can an issue be ushered directly into any known status by name? must issues be walked through all workflow positions before a destination status can be obtained?

Thanks Everyone,

Ryan.

5 answers

1 accepted

5 votes
Answer accepted
You should transition an issue as here: https://answers.atlassian.com/questions/21590/how-to-get-status-object-by-id just setting the status does not updste the osworkflow framework tables which is essential to remember the position within the workflow. Also it won't update your changehistory and you can't figure out later how your issue got into the status.Using transitions also makes sure that your issues are reindexed properly when it's in the new state and thus can be found by filters. In a nutshell you will loose a lot of functions when you bypass the transition. Just look at all the workflow post functions ..l

that helped allot, thanks...

private boolean transitionIssue(Issue issue) {

		boolean result = false;
		IssueService issueService = ComponentManager.getInstance().getIssueService();
		IssueService.IssueResult transResult;
		int actionId = 0;
		
		IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
		
		TransitionValidationResult validationResult = issueService.validateTransition(user, issue.getId(), actionId, issueInputParameters);
		result = validationResult.isValid(); 
		if (result) {
			transResult = issueService.transition(user, validationResult);
		}
		return result;
	}

one more thing though, what the heck is the actionID for?

Each transition has a unique identifier. This identifier must be passed as actioniD. Check the picture at http://confluence.atlassian.com/display/JIRA/Configuring+Workflow#ConfiguringWorkflow-workflowtransitions, e.g. the transition " start progress" has actionID 4. I.e. to move the issue from status open to in progress you must pass that actionD 4

is there a way to get the Transion by name?

You can enumerate the available actions for an issue usinghttp://docs.atlassian.com/jira/4.4.1/com/atlassian/jira/issue/IssueUtilsBean.html#loadAvailableActions(com.atlassian.jira.issue.Issue) Just loop through the result and compare the name In the ActionDescriptor to the name you want to look up

Is there any API, which tells me the actionId based on current Issue status and new status? E.g. issue is in Open state and I want to change it to In progress -> what would be the actionId?

must issues be walked through all workflow positions before a destination status can be obtained?

Yes you must. You can't jump over statuses if there is no such path in the workflow. This makes sense because all the post functions/conditions/validations should all be statisified on the way!

A Source example would be an invaluable gem, please :)

Nothing I have seen provides Java examples that a newby can easily digest.

Hi,

I have the similar requirement and i could achieve moving issue from current status to the target status (if there is a direct Transition/Action configured). But my requirement is, if there is no direct transition from current status to target status, it should figure out all the possible paths and take optimum path to reach the target status. Somehting similar to the "The salesman problem". I have the data/maps available like all possible transitions from each of the step/status, all transitions that lead to a step. How can we use this data to move to the target status. As it is an import tool, the path of status transitions does not really matter. Could someone help here.

 

Thank you,

Rk

@Ramakrishna Siriki

I would caution against your design and debate the validity of your use case a bit, but you can always use, even hide with conditions, a global transition to a known status.  The jiraWorkflow.getDescriptor() will give you a traversable workflow but getting through it can be tricky as workflows are transactional and "diverting" or redirecting is fraught with problems.

For those who are searching for answer that is more up to date in 2017.

Answer is HERE.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 09, 2019 in Portfolio for Jira

Portfolio for Jira 3.0 is here!

The wait is over... Portfolio for Jira Server and Data Center 3.0 is now officially here! Platform releases offer Atlassian an opportunity to shift our strategy, make bold predictions about t...

1,632 views 14 26
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you