Forums

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

Script for Restrict by Workflow Action Doesn't work

Vanessa Conceição de Sousa August 29, 2019

I use this article to restrict resolutions by IssueType using Behaviour, but it doesn't work.

https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-priority-and-resolution.html

 

I change my parametres as the code bellow and when I do a test, still appear all resolutions,.

 

my script:

 

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

if (getActionName() == "Close Issue") {
def constantsManager = ComponentAccessor.constantsManager
def allowedResolutions = constantsManager.resolutions.findAll {
it.name in ["Duplicated"]
}

getFieldById("Resolution").setFieldOptions(allowedResolutions)
}

 

 

1 answer

0 votes
PD Sheehan
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.
August 29, 2019

 

Have you tried with getFieldById("resolution")? System field ids are generally all lowercase.

Or, correct your import and use the correct RESOLUTION (without quotes)

import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION
getFieldById(RESOLUTION).setFieldOptions()
Vanessa Conceição de Sousa August 30, 2019

Hello Peter,

Thanks for your reply.

 

I already tried that, but it didn't worked.

 

I'm having some problems with behaviour scripts that it's working in another instances and in this partilary it's not for some reason.

 

I think maybe the problem is with my version.

 

Jira: 7.6.1

 

ScriptRunner: 5.2.2

PD Sheehan
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.
August 30, 2019

Then the next step is to output some logs.

Also, you have to convert your allowedResolutions into a Map object

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

log.debug "Behavior Test - actionName= ${getActionName()}"
if (getActionName() == "Close Issue") {
def constantsManager = ComponentAccessor.constantsManager
def allowedResolutions = constantsManager.resolutions.findAll {
it.name in ["Duplicated"]
}
log.debug "Behavior Test - allowedResolutions = $allowedResolutions"
def resolutionMap = allowedResolutions.collectEntries{[(it.id ): it.name
log.debug "Behavior Test - resolutionMap = $resolutionMap"
getFieldById("resolution").setFieldOptions(resolutionMap)
}

Suggest an answer

Log in or Sign up to answer