Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,348
Community Members
 
Community Events
176
Community Groups

update issue status in java

Edited

hi,

I have created a Java tool that creates a Jira operational task for a parent issue. i want to set the status of operational tasks with using RestAPI directly of "Done". but i could not find a correct way or method to do it!

maybe someone have a suggestion for me?

Thanks

4 answers

2 accepted

0 votes
Answer accepted

You should issue a REST call to transition the issue from one state to another.  See https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&utm_medium=302#about

0 votes
Answer accepted
Joe Pitt Community Leader Apr 08, 2020

Done requires two things whether you do it in the UI or with an API; 1. the resolution field to be set along and 2. the status must be in the filter requirement for done.  You need to find out what the status requirements are for done and set the resolution field

I got this problem too. Then I google a lot, did not find any useable solution. So I read the sdk code, find out that it is pretty simple.

please make sure you use the same version of Jira Java SDK with mine:

<dependency>
     <groupId>com.atlassian.jira</groupId>
     <artifactId>jira-rest-java-client-core</artifactId>
     <version>5.1.6</version>
</dependency>
<dependency>
     <groupId>io.atlassian.fugue</groupId>
    <artifactId>fugue</artifactId>
    <version>4.7.2</version>
</dependency>



/**
* update jira issue status
* status: like "Done"
*/
public void updateIssueStatus(Issue issue, String status) {
IssueRestClient client = getJiraRestClient().getIssueClient();

Iterable<Transition> transitions = client.getTransitions(issue).claim();

for(Transition t : transitions){
if(t.getName().equals(status) {
TransitionInput input = new TransitionInput(t.getId());
issueClient.transition(issue, input).claim();

return;
}
}
}


// you can ignore below if you know how to get IssueRestClient and Issue

public JiraRestClient getJiraRestClient() {
AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();

JiraRestClient client = factory.createWithBasicHttpAuthentication(URI.create(JIRA_URL), JIRA_USER, JIRA_PASSWORD);

return client;
}

public Issue getIssue(String issueKey) {
IssueRestClient client = getJiraRestClient().getIssueClient();
return client.getIssue(issueKey).claim();
}
  

 

thank you @wxweven , I was looking for Status update and this is the best solution worked as magic.

Works like a charm.

Modifying a bit to @wxweven  answer:

Changing status can be tricky depending on the process your company has put in place. Status change is actually a change in the issue transition (Ex. "In Progress Dev" to "Ready for Review" to "Done"). Your company can mandate, for example, if status needs to be changed to "Done" resolution filed must be changed to "Fixed" or "Done" etc. If so, you may need to set the resolution on the go while changing the status. Here is the code with modified updateIssueStatus method:

 

public void updateIssueStatus(Issue issue, String status) {
IssueRestClient client = getJiraRestClient.getIssueClient();

Iterable<Transition> transitions = client.getTransitions(issue).claim();

final Collection<FieldInput> fieldInputs;
fieldInputs =
Arrays.asList(new FieldInput("resolution", ComplexIssueInputFieldValue.with(
"name", "Done")));


for(Transition t : transitions){
if(t.getName().equals(status)) {
TransitionInput input = new TransitionInput(t.getId(),fieldInputs);
client.transition(issue, input).claim();

return;
}
}
}

 

Please note that if resolution field is not in the "edit JIRA" screen, you may get below error:

 

Exception in thread "main" RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={resolution=Field 'resolution' cannot be set. It is not on the appropriate screen, or unknown.}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(..............)

 

In such scenario you may need to discuss to your JIRA admin to make resolution field visible in "edit jira" screen.

 

Hope this helps.. Thanks.

Hello Pandey, Can you explain how to make the resolution field visible in edit JIRA screen. My JIRA Admin says that the field is visible, but I'm still getting the same error. Please help

Suggest an answer

Log in or Sign up to answer