Forums

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

Change "Issue Type" based on custom "Cascading List" field

Lakshmi CH
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.
July 24, 2023

Hi Team,

I need to change the "Issue Type" based on the custom "Cascading List" field. The code I am using is working correctly. When I change the custom field value to A - A1, the issue type also changes to A. However, the second value of the custom field, A1, is changing back to "None" instead of staying at A1. Is there a mistake in the script?

I utilized script runner behavior and server script.

 

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours behaviours
def issueType = getFieldById(ISSUE_TYPE)
def cascadecustomField = getFieldByName("Cascading Custom Field")
def selectedOptions = cascadecustomField.getValue() as Map


def ParentOption = selectedOptions.get(0).toString()
def ChildOption = selectedOptions.get(1).toString()


if(ParentOption == "A" && ChildOption == "A1")
{
  issueType.setFormValue('B')
}
if(ParentOption == "B" && ChildOption == "B1")
{
  issueType.setFormValue('B')
}
both.PNG
birpt.PNG

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 25, 2023

Hi @Lakshmi CH

For your requirement, you should modify your code to something like:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours behaviours
def cascade = getFieldById(fieldChanged)
def cascadeValue = cascade.value
def issueType = getFieldById(ISSUE_TYPE)
def currentValue = []

if (cascadeValue == ['Story', 'Story 1']) {
issueType.setFormValue('Story')
currentValue = ['Story', 'Story 1']
} else if (cascadeValue == ['Bug', 'Bug 1']) {
issueType.setFormValue('Bug')
currentValue = ['Bug', 'Bug 1']
}

if (currentValue.size() > 0) {
cascade.setFormValue(currentValue)
}

However, this is not an approach I would recommend. The reason is once the issue type has changed according to the option selected from the Cascading List, it will not be able to change again. You will need to create an issue from scratch.

It would be best to only set the Parent value of the cascading list as it is currently working.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram 

Lakshmi CH
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.
July 25, 2023

Thank you @Ram Kumar Aravindakshan _Adaptavist_ for correcting my script. It's working; expected now.

birpt_script.PNG

Lakshmi CH
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.
July 27, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

The issue type doesn't change if the child value is "None" ?

 

if (cascadeValue == ["Story", "None"]) {
 issueType.setFormValue("Story")
 currentValue = ["Story", "None"]
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 28, 2023

Hi @Lakshmi CH

The approach you are taking is wrong.

If you want to set the condition for only the Parent list and the Child list being None, all you have to do is:-

if (cascadeValue == ['Story']) {
issueType.setFormValue('Story')
}

I hope this help answer your question. :-)

Thank you and Kind regards,
Ram 

Like Lakshmi CH likes this
Lakshmi CH
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.
July 28, 2023

Suggest an answer

Log in or Sign up to answer