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
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Richu Ann Babu No, the post function will not be executed, so you would have to take that into consideration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.