Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

update issue status in java

Deleted user April 8, 2020 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
Nic Brough -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.
April 8, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 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

2 votes
wxweven
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2021 edited

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

 

Jyothi Gajula September 21, 2021

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

Jake Heidlage
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 27, 2022

Works like a charm.

0 votes
ved pandey
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 28, 2021

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.

BUVANESHJ
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 5, 2021

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
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events