Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,398
Community Members
 
Community Events
165
Community Groups

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

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

1 vote
Answer accepted

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,

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

Thanks,
Martin

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,443 views 37 44
Read article

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