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);
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need same, but for cloud. Can it work ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.