Script runner groovy to change issue type if certain description is added

Martin Benavides June 1, 2022

Hi good day community,

Requesting your help on this please:

I am trying to find the right groovy script to change an issue type from one to another ONLY if certain criteria is met. Once an issue is created, if the Description contains the word "bug", this script should run and change the issue type from Story to Bug. I am trying to add it in a post function in the transition Create but I know some things in my script are not there ( I am a newby in Scriptrunner scripts)

Could some one please help me out?

Is not too much but this is what I have now:

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


if (issue.getDescription().contains("Bug") {

MutableIssue issue = issue;
if(issue.issueType.name == "Story") {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Bug"};
if (newIssueType) issue.setIssueTypeObject(newIssueType);
}

}

1 answer

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _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.
June 2, 2022

Hi @Martin Benavides

For your requirement, you could try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def description = issue.description
def constantsManager = ComponentAccessor.constantsManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.issueManager

def issueType = constantsManager.allIssueTypeObjects.find {it.name == 'Bug' }

if (description.toLowerCase().contains('bug')) {
issue.setIssueType(issueType)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

Please note that this is not 100% exact to your requirement.  Hence, you will need to make the required modifications.

I hope this helps to solve your question. :)

Thank you and Kind regards,

Martin Benavides June 9, 2022

Thank you for your help Ram, it is working as expected. Have a good one!

Thanks,
Martin

Gal Fatal
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 8, 2024

Hi @Martin Benavides  

I need same, but for cloud. Can it work ?

Suggest an answer

Log in or Sign up to answer