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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Works like a charm.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.