How to change issue type and status with Groovy ScriptRunner? Edited

I would like to code the following in Groovy:

- Change type for issue I from type T1 to type T2

- Since type T1 and type T2 have different workflow, I also need to set the status for issue I to one of the status included in the workflow for type T2.

- For simplicity, let's assume that whenever I change the type of an issue from T1 to T2, I want set the status of the issue to S1 (which is one of the status included in the workflow associated to the type T2).

 

So far I have been able to change issue type via

issue.setTypeId()

issue.store()

 

Since the type T1 and type T2 have two different workflows associated with them, I cannot use transitions to change the status.

So I tried to change the status id in the following way:

issue.setStatusId()

issue.store()

but this appears not to be enough. When I execute a transiton, the status transition to a status of the old workflow rather than the new one.

Any ides?

1 answer

This widget could not be displayed.

You can't set a status because it's not a field, it's an indicator of the issue's position in the workflow.

To change the status, you have to transition the issue through the workflow to land on the step you need to get it to.

Hi Nic, I edited the questions trying to clairfy more the details.
The issue is that the two type have different workflows associated with them so I cannot use transitions to change the status.

Roberto Saltini

Ok, so you're trying to move an issue from one issue type to another, one that has a different workflow.

This is not a simple task, the only time you can do a simple "set" of the issue type is when the two issue types have compatible configurations.  In this case, they do not.

Your code is going to need to replicate all the checks and processes that the full "move issue" process does when a user  does it in the UI.

Hi Nic,

Where can I find these processes? In the JIRA source code only?

 

Also, I was thinking to the following hack:

Since I am only interested in moving an issue from a type with workflow WF1 to a type with workflow WF2, I was thinking to add one of the statuses (SC) included in WF2 to WF1, so that when I need to do the move a first transition the issue to status SC and then I change the type.
At this point the issue has changed type and is in a valid status for the new workflow (WF2).

What do you think about this?

It's not just the workflow that matters, you need it to do all the checks and changes.  It's a nice idea that you can just have the same status, but that's not the problem, it just means you don't have to do the mapping (and you could easily do the mapping in your code anyway).

You will need to dig through the API to find the move stuff, yes.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 14 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

41 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you