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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Filter or Set Epic Link Based on Custom Field Selection Edited

Is there a way to filter options in the Epic Link selector based on the combination of the issue type and the selection of another custom field, specifically a Cascading Select Custom field? (And maybe using a ScriptRunner Behavior). :) 

Here's my example:

I have a couple of issue types: Design and Make. 

I have a custom field that is a Cascading Select List. I'll call this field Purpose. 

Purpose Parent Options: 

  • A
  • B

If A is selected, Child Options:

  • 1
  • 2

If B is selected, Child Options:

  • 1
  • 3

The issue reporter chooses Design as the issue type and then selects A and then 1 from the Purpose field drop-down.

Then, the Epic Link field appears with a whittled down Epic Link selection (because we have so many):

  • DESIGN A1 - Dev
  • DESIGN A1 - Build

Is there a way to add a Behavior script that limits the Epic Link options based on these user inputs?

Alternatively, is there a way to just set the Epic Link based on a combo selector?


1 answer

1 accepted

1 vote
Answer accepted

Well, this was an interesting one to solve.  Rather than using a Behavior, we used a Script Listener to actually set the Epic Link value based on the inputs from the Multi-Level Cascading Selector.

Using the original example I started with, the name of my MLCS Custom Field is "Purpose".

The options in the first drop-down of the selector are A, B

  • If A, then the next options are 1,2.
    • If A1, then the third options are Dev and Build.
// Import Necessary Items
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent

// Set up the Change Event
def changedPurpose = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field.toString().substring(0,2) == "PURPOSE"}
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

//Get Data From "PURPOSE" Custom Field. The PURPOSE Custom Field ID is 11123.
def mlcs = customFieldManager.getCustomFieldObject("customfield_11123")
ArrayList<String> mlcsValues = (ArrayList<String>) issue.getCustomFieldValue(mlcs)
String[] mlcsValuesList = mlcsValues.toArray()

// Set up more variables to grab the Issue Type and a random Epic Key
def issueType = issue.getIssueType().id
def componentIssue = issueManager.getIssueObject("")
def strEpicKey = "SOME EPIC KEY HERE (Ex: PROJ-123)"

//Determine the Epic Links Based on the Values in the selector.

//If the combo is "A - 1 - Dev"
if (mlcsValuesList[0] == 'A' && mlcsValuesList[1] == '1' && mlcsValuesList[2] == 'Dev') {
//Design Issue Type
if (issueType == '11100') { strEpicKey ='EPIC KEY HERE (Ex: PROJ-124)';}
//Other Issue Type
if (issueType == '11101') { strEpicKey ='EPIC KEY HERE (Ex: PROJ-125)';}

//...Continue the format above for all the Epic Links and selector
//options you may use

//Now, you need to actually set the Epic Link Value for the Issue
def epicIssue = issueManager.getIssueObject(strEpicKey)
def epicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")[0]
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())

I hope someone finds this helpful.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you