How to restrict Resolutions the example script from script runner does not work.

ChristopherChilds
Contributor
March 25, 2021

Hello,

Using Jira 8.13.1 Server

I have a project where the use wants to restrict the number of Resolutions available. The total list of Resolutions available are over 25. This is too many,

So one project wants to restrict this for all issue types. The workflow has 8 statuses and they allow any status to transition to any other status.

I copied the script from the scriptrunner website and changed it but for some reason this is not working on the view Issue. It only works when i am in the Edit ticket screen.
This is strange because Create, View and Edit are all the same screen.


I have the following script:

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def constantsManager = ComponentAccessor.getConstantsManager()
def allowedResolutions = constantsManager.getResolutionObjects().findAll {
    it.name in ["Won't Fix", "Incomplete", "Cannot Reproduce"]
    }.collectEntries {
        [(it.id): it.name]
    }
getFieldById(RESOLUTION).setFieldOptions(allowedResolutions)



3 answers

2 accepted

0 votes
Answer accepted
Daniel Ebers
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 5, 2021

Hi @ChristopherChilds

maybe I am missing the advantages of Script Runner for doing this particular job - but have you had a look into workflow properties?
They also can be used to restrict which resolution is offered in a specific workflow:
https://confluence.atlassian.com/adminjiraserver087/workflow-properties-998872279.html

I seem to understand you have several transitions in a likely complex workflow but what Taranjeet says is true from my view also - the setting should only apply to transition screens leading to a done/close status.
So, you would have to evaluate if this alternative approach using workflow properties work better over the Behaviours implementation.

Regards,
Daniel

0 votes
Answer accepted
Fabio Oliveira Silva March 25, 2021

Hello, @ChristopherChilds this code is set on Behavior right? In this case, the code cannot be applied on the View screen as documented here 

One alternative can be to remove this to the Edit screen, which avoids this field to be edited on the View screen, and add a resolution screen on Closing transitions

ChristopherChilds
Contributor
March 25, 2021

Thanks for the update. Can you just clarify what you mean by "remove this to the Edit screen"? The project uses the same screen for Create, Edit and View

Fabio Oliveira Silva March 25, 2021

Hi, @ChristopherChilds just create a copy of the screen, remove the resolution field and associate the new screen with the Edit operation on Screen Scheme. This guide can help you do this task if you need it. 

Taranjeet Singh
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2021

I think what @Fabio Oliveira Silva means to say is that the new screen (without the Resolution field) should be associated to the Edit Issue operation in the Screen Schemes for all issue types in the project. This won't allow Resolution to be editable, even from the View issue screen. The Resolution will be displayed on View Issue screen though.

Also, as @Fabio Oliveira Silva suggested, you should keep the Resolution field editable only on transition screens leading to Done or Closed statuses.

0 votes
Thales Deutschland
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 24, 2023

Hi, @ChristopherChilds, I also used the same code in behaviors for restricting resolutions. It worked fine with Jira-8. Now we upgraded to Jira-9 and it complains:

it.name in ["Won't Fix", "Incomplete", "Cannot Reproduce"] - is not existing any more

constantsManager.getResolutionObjects() - is no more available 

Do you have any suggestions how to overcome this problem?

Becky December 12, 2023

Hello @Thales Deutschland

Our team encountered the same challenge today, and the following code works for us:

 

    def allowedResolutions = constantsManager.getResolutions().findAll {
        it.name in ["Passed", "Failed", "Waived"]
    }

More details about constantsManager class can be found here (you should change the Jira version in the URL to your Jira Software Version): https://docs.atlassian.com/software/jira/docs/api/9.4.12/com/atlassian/jira/config/ConstantsManager.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events