Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

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

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

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

 

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you