How to set jira issue type with script runner

Adolfo Casari
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.
February 15, 2013

Hi,

I am using script runner to create a new issue, need to set its type to "mytype"...but I am stuck.

Any help?

Thank you!

2 answers

1 accepted

1 vote
Answer accepted
Darly Senecal-Baptiste
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.
April 23, 2013
VINSTON WEN October 11, 2020

yes, I  do it. but .... The issue type does change, but the workflow seems to only be partially migrated. The View Workflow button on the issue does show the new workflow, but no workflow buttons are available.

0 votes
Joe Smith July 14, 2015

I need to do this too.  The link above does not work for me.  If use this code, it IS getting the newIssueType, but is not able to change the issue type:

{code}
import com.atlassian.jira.component.ComponentAccessor

def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Information Only Change"}
if (newIssueType) issue.setIssueObject(newIssueType)

{code}
Error:
No signature of method: com.atlassian.jira.issue.IssueImpl.setIssueObject() is applicable for argument types: (com.atlassian.jira.issue.issuetype.IssueTypeImpl) values: [com.atlassian.jira.issue.issuetype.IssueTypeImpl@e09d6de4] Possible solutions: getIssueObject(org.ofbiz.core.entity.GenericValue), setIssueTypeObject(com.atlassian.jira.issue.issuetype.IssueType
Sergey Balakhonov March 16, 2021

You have to use MutableIssue class, not Issue.
Issue for getting info only, MutableIssue for both: getting and changing your issue.

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

// get issue by key for example
MutableIssue
 issue = ComponentAccessor.getIssueManager().getIssueObject('ABC-123')

def
 newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.getProjectObject()).find{it.getId() == "3"}
issue.setIssueTypeObject(newIssueType)

// update issue for saving changes
ComponentAccessor.issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)

 

Suggest an answer

Log in or Sign up to answer