Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira Behavior "Initialiser Function" can't set Resolution field

Brent Webster
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.
September 16, 2015

I want to use the Resolution field as a sub-Status field for all Statuses not just Resolved.  I'm using the Initializer function to default and only allow one resolution menu item: "Screening Required" when a new issue is being created.  The "Screening Required" menu item does show up as the only item for Resolution field but when the issues is created, the Resolution field shows up as "Unresolved".  Any ideas?

 

This code is based on https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-priority-and-resolution.html

import com.atlassian.jira.component.ComponentAccessor;
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION
import com.atlassian.jira.ComponentManager
 
def issueId = formContents["id"]
if (issueId == null ) {
  // no issue key so new issue being entered
  def resolutionField = getFieldById(RESOLUTION)
  def constantsManager = ComponentAccessor.getConstantsManager()
  def allowedResolutions = constantsManager.getResolutionObjects().findAll {
    it.name in ["Screening Required"]
  }.collectEntries {
    [(it.id): it.name]
  }
  resolutionField.setFieldOptions(allowedResolutions)
}

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2015

You do know that if you do this, ALL your issues will be resolved at all times?  The internal reporting becomes pretty much useless?

JamieA
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.
September 16, 2015

Well... JIRA treats the resolution field as special, in a very binary way. You are better of doing this with a select list custom field.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2015

Yep, shame we can't +1 comments ;-)

Brent Webster
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.
September 16, 2015

I realize I technically can't use jql: "resolution = unresolved" by itself anymore and that I must qualify all my searches with both "status = xxxx and resolution = yyyy" etc but I'm OK with that. Is this special "very binary way" of handling Resolution going to shoot me in the foot? Does that include not being able to default the Resolution field in the Create action?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2015

You can default the resolution on the screen. What we're getting at is that your issues will all be resolved at creation time. JIRA will treat them as closed in all the hard-coded reports you can't change. Some gadgets will be useless (created vs resolved is an obvious one). Agile REALLY won't work if you have it. Portfolio will report all your projects as completed all the time.

Brent Webster
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.
September 16, 2015

Good points -- rethink time.

JamieA
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.
September 16, 2015

I have done what you're talking about with a simple select list field... worked ok.

Brent Webster
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.
September 16, 2015

Everything is simple but I'm an old C/Perl/bash hacker. My simple select list field isn't looking so simple. I created a new custom field: subStatus and populated it with some of the menu items matching the Resolution field. This behaviour initializer script will enable two of the menu items as a test but in the end, I'm still seeing all the menu items. {code} package com.onresolve.jira.groovy.user import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager public class ScriptSample extends FieldBehaviours { public void coriantInitsubStatusField () { CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager(); def issueId = formContents["id"] if (issueId == null ) { // creating new issue so hide subStatus and set it in the post-function for the Create action subStatusField.setHidden(true) } else { // existing issue Resolution defined based on Status def subStatusField = getFieldByName("subStatus") def issue = ComponentManager.getInstance().getIssueManager().getIssueObject(issueId as Long) def currStatus = issue.status.name List filteredSubStatuses = ["Screened", "Under Analysis"] Map allowedOptions = new HashMap(); def sSObj = customFieldManager.getCustomFieldObjectByName('subStatus') for (def anOption:sSObj.getOptions(null, sSObj.getRelevantConfig(issue), null)) { if (filteredSubStatuses.contains(anOption.getValue())) { allowedOptions.put(anOption.getOptionId(), anOption.getValue()) } } for (def aKey: allowedOptions.keySet()) log.warn "<<BW>> ID = " + aKey + ", NAME = " + allowedOptions.get(aKey) subStatusField.setFieldOptions(allowedOptions) } } } {code} The logs: 2015-09-16 18:05:37,233 http-bio-8080-exec-12 WARN SwMgrA 1085x17510x1 avxjhg 192.168.109.121 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json [jira.groovy.user.FieldBehaviours] <<BW>> ID = 10201, NAME = Screened 2015-09-16 18:05:37,233 http-bio-8080-exec-12 WARN SwMgrA 1085x17510x1 avxjhg 192.168.109.121 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json [jira.groovy.user.FieldBehaviours] <<BW>> ID = 10202, NAME = Under Analysis More help would be appreciated. Thanks Brent

JamieA
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.
September 16, 2015

Couple of problems... in the "if (issueId == null)" bit you haven't declared or initialised subStatusField, although you have done in the "else" block". Just move the declaration above the "if". Then log.warn the value of substatus field. It needs to be exact name and case, ie if your field is really called "Sub-status" it should be that.

0 votes
Brent Webster
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.
September 17, 2015

Got it working using a separate "subStatus" custom field.  Thanks Jamie and Nic for your help

package com.onresolve.jira.groovy.user

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager

public class ScriptSample extends FieldBehaviours {

    public void coriantInitsubStatusField () {
        CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();

        def issueId = formContents["id"]
        def subStatusField = getFieldByName("subStatus")
        if (issueId == null ) {
            // creating new issue so hide subStatus and set it in the post-function for the Create action
            subStatusField.setHidden(true)
        } else {
          // existing issue Resolution defined based on Status
            def issue = ComponentManager.getInstance().getIssueManager().getIssueObject(issueId as Long)
            List filteredSubStatuses = ["Screened", "Under Analysis"]
            Map allowedOptions = [:]
            def sSObj = customFieldManager.getCustomFieldObjectByName('subStatus')
            for (def anOption:sSObj.getOptions(null, sSObj.getRelevantConfig(issue), null)) {
                if (filteredSubStatuses.contains(anOption.getValue())) {
                    def anID   = anOption.getOptionId() as String
                    allowedOptions.put (anID, (anOption.getValue()))
                }    
            }
            subStatusField.setFieldOptions(allowedOptions)
        }
    }
}
TAGS
AUG Leaders

Atlassian Community Events