Forums

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

How do I make both Cascading fields required based on an issue-type

Luvo Hubela September 11, 2020

I have an issue-type of "Task" and it shares the same workflow as bug, epic and story.

I have this cascading field and i only want both fields (in cascading CF) to be required only in Task issue type not in bug, story and epic.

I have a piece of code that i added as a validator on create (workflow).

2 answers

1 accepted

0 votes
Answer accepted
Luvo Hubela September 17, 2020

i managed to resolve this by using the following script

import com.atlassian.jira.component.ComponentAccessor  

import org.apache.log4j.Logger
import org.apache.log4j.Level  

log.setLevel(Level.INFO)  

if (issue.issueType.name == 'Issue-type') {       

def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find{ it.name == "cascading_field" }    

def values = issue.getCustomFieldValue(cascadingSelect) as HashMap       if (values?.keySet() != null && values?.keySet()?.size() == 2) {
        for ( String k : values?.keySet() ) {
           if ( k == 'null' ) return false
        }
        return true
        
    }
    
    return  false
}

0 votes
Joe Pitt
Community Champion
September 11, 2020

Use different field configurations.

Yes, as long as it is a different issue type. Required fields, at creation time are controlled by the field configuration scheme. That scheme is composed of one or more field configurations. Every issue type can have its own field configuration inside the field configuration scheme. If you have 5 issue types and 1 has special needs you create a field configuration for the 4 issue types and another for the 1 issue type. Then you combine them into a field configuration scheme and apply that to the project. When an issue is created, it looks for a field configuration for that issue type and uses it. If it doesn't find one it uses the default in the configuration scheme.  Copy/paste this link for more information. https://confluence.atlassian.com/adminjiracloud/configuring-a-field-configuration-scheme-844500805.html 

Luvo Hubela September 11, 2020

Hi @Joe Pitt 

I have the field required for Task issue-type using Behaviours.

I then created a validator on the workflow. 
this is my script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

if (issue.issueType.name == 'Task') {

def Issue = issue as MutableIssue
def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("Classification")
def values = issue.getCustomFieldValue(cascadingSelect) as HashMap

// Will return true if both the parent and child options in the Cascading Select have a value
values?.keySet()?.size() == 2
}

the script works fine for issue-type "Task".

The problem I have is that for some issue-types like bug, when I create an issue the complain about the missing values on the classification field.

Luvo Hubela September 11, 2020

cascading.PNG

Joe Pitt
Community Champion
September 11, 2020

I don't use scripting so I can't help.

Like Luvo Hubela likes this

Suggest an answer

Log in or Sign up to answer