Forums

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

Scriptrunner Behaviour Initialiser Allowed List Field

Justin
Contributor
December 18, 2018

Hi all -

I have a Behaviors script that was slightly modified from the user documentation. This essentially looks for an issue type and updates the list of resolution values the user can choose from (and hides the others) when they try to move it to Done status.

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

if (issueContext.issueType.name == "Bug") {
def constantsManager = ComponentAccessor.constantsManager
def allowedResolutions = constantsManager.resolutions.findAll {
it.name in ["Code Change", "Cannot Reproduce", "Will Not Do]
}

getFieldById(RESOLUTION).setFieldOptions(allowedResolutions)
}

My only issue with this is that it currently sets a default value vs. forces the user to select from the list (Please select...). Is this possible? From my research it ignores values entered that don't exist in the system. Thank you

resStatus.png

 

 

1 answer

1 accepted

1 vote
Answer accepted
Carmen Creswell [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.
December 18, 2018

Hi Justin! 

So, since you have restricted the values that can show up in the "Resolutions," the "Please select..." no longer shows up there. There is a (kind of hacky) way to get around this. You can add a new Resolution called "None" at the top of your Resolutions and allow it to show up as one of the restricted values in the code that you put here (just add it to the list you have already). Then, you can add a Validator (Workflows -> 'Edit' on the correct workflow -> 'Resolve issue' transition -> Validator) that checks that one of the proper values has been selected as a resolution. You'll want to use a Simple Scripted Validator and put this in the Condition box: 

issue.resolutionObject.name != "None"

Hypothetically, you could name your resolution "Please select...," but that would likely cause more confusion, especially if you have projects that don't use the Behaviour that restricts the selection options. 

Justin
Contributor
December 18, 2018

Hi Carmen Thanks for your response! Yes, that's exactly what I am running into.

My concern about the approach you recommend would be that other users, projects, etc. would now start to see the None resolution option (and probably pick it...somehow someway) unless I added the Initialiser script on every workflow -- we have lots!

Another thought I just had, rather than constrain the options that show up, perhaps I could show the full list and only allow certain resolution statuses to be selected? That would still allow for the "Please select..." option forcing them to make a choice. Thoughts on this approach?

Carmen Creswell [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.
December 18, 2018

That approach sounds to me like it would work! You can use a Validator the same way I described before to implement that. Something to note is that in the error message that will come up if a user selects an invalid Resolution, you should probably include which resolutions are allowed to be selected for that project. Something like "Please choose one of the following Resolutions..." so that users know why they aren't allowed to Resolve the issue. 

Suggest an answer

Log in or Sign up to answer