Need a script in a post function that depending on a custom field value changes the Issue Type.

We require a scriptrunner script that allows us to change the issue type in a post function called TRIAGE, based on the contents of a cascade select custom field that will have two linked values, such as Application -> Desktop Support, that will then change the Issue type to Desktop Support.

The initial state for the Issue Type would be TRIAGE, there will be around 20 different issue types based on the contents of the custom field.

Anyone have any examples on how to change the Issue Type? I have been looking and havent found anything directly scripting this type of change.

Thanks

 

1 answer

This script should work.

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cascadingSelect = customFieldManager.getCustomFieldObjectByName("CascadingSelect")
def cascadingOptions = issue.getCustomFieldValue(cascadingSelect) as Map
def cascadingValues = [cascadingOptions.get(null) as String, cascadingOptions.get("1") as String]

if (cascadingValues == ['Application', 'Desktop Support']) {
issue.setIssueTypeId("10101") // issue type id here
}
else if (cascadingValues == ['Application', 'Desktop Support']) {
// and so on
}
else {
// and so on
}

You'll just have to add more else if blocks. You'll also need to have the correct issueTypeId to use (https://confluence.atlassian.com/display/JIRA050/Finding+the+Id+for+Issue+Types)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you