Programatically Modify/Change/Update an issues status in Java

ryan McCullough March 27, 2012

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.

6 answers

1 accepted

5 votes
Answer accepted
Dieter
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.
March 27, 2012
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
Dieter
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.
March 27, 2012
ryan McCullough March 27, 2012

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;
	}

ryan McCullough March 27, 2012

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

Dieter
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.
March 27, 2012
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
ryan McCullough March 27, 2012

is there a way to get the Transion by name?

Dieter
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.
March 27, 2012
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
Roman Theuer December 15, 2014

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?

1 vote
Jobin Kuruvilla [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.
March 27, 2012

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!

ryan McCullough March 27, 2012

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

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

0 votes
Roman Samorodov
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.
January 16, 2017

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

Answer is HERE.

0 votes
Steven Kling September 24, 2016

@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.

0 votes
Ramakrishna Siriki March 15, 2016

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

Suggest an answer

Log in or Sign up to answer