Need to change Issuetype to another Type automatically when the workflow transition got executed

Kumar
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 16, 2019

Hi Team,

I have to change my Issuetype  to another issue type automatically when the Workflow transition got executed.

Example:

I have 2 issutypes in one project "A and B" now when the A issue got created I have a Transition called "Approve" in workflow so when the user execute that "Approve" button on issue The "A" issue need to convert to "B" issue automatically.

 

Could you please anyone help me how to achieve this

 

Thanks,

Kumar

1 answer

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2019

You can do this by using a post function on the Approve transition. I use this script to do the same thing for one of my projects:

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

MutableIssue issue = issue;
if(issue.issueType.name == "A") {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="B"};
if (newIssueType) issue.setIssueTypeObject(newIssueType);
}
Kumar
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 16, 2019

Hi @Mikael Sandberg  Thanks for your script its working perfect

 

Thanks,

Kumar

Nick Eden July 11, 2019

@Mikael Sandberg Nice script. Works for us, but limited to only being able to set 1 issue type.

I want to do something similar to this, but add the flexibility to choose/set a specific issue type based on some logic (within the same project)

So say we have issue type A, that needs to be moved into either B, C or D.

During the transition could I set a custom field value manually via a screen (B, C, D) that then the script could identify and apply:

For example if value = B, set to issuetype B

For example if value = C, set to issuetype C and so on.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2019

@Nick Eden Yes, you could change the field the script looks at to determine what issue type it should be, all you have to do is change the if statement.

Nick Eden July 11, 2019

@Mikael Sandberg thanks, can you give an example..im not the best scripter :D

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2019

@Nick Eden I am know just enough groovy to be dangerous ;). Here is an example of what the code would look like:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.customfields.option.Option;

MutableIssue issue = issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def customField = customFieldManager.getCustomFieldObject("customfield_xxxxx"); // My custom field
def customValue = issue.getCustomFieldValue(customField) as Option;

if(customValue.value == "A") {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="A"};
if (newIssueType) issue.setIssueTypeObject(newIssueType);
}
else if(customValue.value == "B") {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="B"};
if (newIssueType) issue.setIssueTypeObject(newIssueType);
}
else {
def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="C"};
if (newIssueType) issue.setIssueTypeObject(newIssueType);
}

The example assumes that the custom field is a select field, and I like to get the custom field by the ID, that way I do not have to worry about changing the script in case you have to rename the field for some reason. 

Nick Eden July 15, 2019

@Mikael Sandberg Great, the script works very nicely. Thanks for this.

However, when the item has moved to the new issuetype/workflow. I dont see any workflow transition buttons available to me.

If I move the task manually, everything is fine.

Im checking to see if there is any workflow/issue inconsistency when using the script, but just wondered if you have come across this before.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 15, 2019

Hmm, I have not seen that behavior before. The only thing I can think of is to check your permission scheme to see if the transition an issue is set to just assignee or something like that. Also like you said, check the conditions in your workflow.

Richu Ann Babu March 30, 2022

@Mikael Sandberg , Will changing the issuetype via script like this, execute the postfunctions of the new issuetype create transition? or should we explicitly add the postfunctions on this conversion transition?

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 30, 2022

@Richu Ann Babu No, the post function will not be executed, so you would have to take that into consideration.

Like Richu Ann Babu likes this
Richu Ann Babu April 5, 2022

Thanks for the info @Mikael Sandberg 

Suggest an answer

Log in or Sign up to answer