Modifying Jira ticket resolution using Java REST client

Hey folks, I’m stuck trying to change a Jira ticket’s resolution when closing it. I’m using the Jira REST Java client, but I’m getting an error. Here’s what I’ve tried:

public static void closeIssue(String issueKey) {
    try {
        JiraIssue ticket = jiraClient.getIssueClient().getIssue(issueKey).get();
        List<IssueTransition> availableTransitions = jiraClient.getIssueClient().getTransitions(ticket).get();
        
        int closeTransitionId = availableTransitions.stream()
            .filter(t -> t.getName().matches("(?i).*(Closed|Done).*") )
            .findFirst()
            .map(IssueTransition::getId)
            .orElseThrow(() -> new RuntimeException("No closing transition found"));
        
        List<FieldInput> fields = Collections.singletonList(
            new FieldInput("resolution", ComplexIssueInputFieldValue.with("name", "Not Feasible"))
        );
        
        TransitionInput transitionInput = new TransitionInput(closeTransitionId, fields, Comment.valueOf("Closing comment"));
        jiraClient.getIssueClient().transition(ticket, transitionInput).claim();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

But I’m getting this error:

RestClientException: Field 'Resolution' cannot be set. It is not on the appropriate screen, or unknown.

Any ideas what I’m doing wrong? Thanks in advance!

I’ve encountered this issue before when working with the Jira REST Java client. The error you’re seeing typically occurs when the resolution field isn’t available on the transition screen for the specific workflow you’re using.

Here’s what worked for me:

  1. Double-check if the ‘Resolution’ field is actually present on the transition screen for closing the issue in your Jira instance. You might need to modify the workflow to include this field.

  2. If the field is present, try using the field ID instead of the name. For example:

new FieldInput("resolution", ComplexIssueInputFieldValue.with("id", "10000"))

Replace “10000” with the actual ID of the resolution you want to set.

  1. Another approach is to set the resolution after transitioning the issue:
jiraClient.getIssueClient().transition(ticket, new TransitionInput(closeTransitionId)).claim();
jiraClient.getIssueClient().update(ticket, IssueInput.createWithFields(new FieldInput("resolution", ComplexIssueInputFieldValue.with("name", "Not Feasible")))).claim();

This separates the transition and resolution update, which might bypass the screen validation issue.

Hope this helps! Let me know if you need any clarification.

I’ve dealt with similar issues using the Jira REST Java client. One thing to consider is that the ‘Resolution’ field might not be editable during the transition process in your specific Jira configuration. To troubleshoot this, you could try updating the resolution separately after closing the issue.

Here’s an alternative approach you might want to try:

jiraClient.getIssueClient().transition(ticket, new TransitionInput(closeTransitionId)).claim();

IssueInputBuilder iib = new IssueInputBuilder();
iib.setResolution(new Resolution("Not Feasible"));
jiraClient.getIssueClient().update(ticket, iib.build()).claim();

This method first transitions the issue to the closed state, then updates the resolution in a separate step. It might bypass the screen validation error you’re encountering. Remember to import the necessary classes for IssueInputBuilder and Resolution. If this doesn’t work, you may need to check your Jira workflow configuration to ensure the resolution field is editable during or after the close transition.

hey mate, ive run into this before. the issue might be with ur jira workflow setup. check if the resolution field is actually available during the close transition. if not, try updating it after closing:

jiraClient.getIssueClient().transition(ticket, new TransitionInput(closeTransitionId)).claim();
jiraClient.getIssueClient().update(ticket, IssueInput.createWithFields(new FieldInput("resolution", ComplexIssueInputFieldValue.with("name", "Not Feasible")))).claim();

hope this helps!