How to get Issue Status using groovy

How to get current Status of Issue Type using groovy and gather the list of linked status for the ticket.

Can anybody help me out with this?

1 answer

to get current status of issue

issue.getStatusObject().getName();

to get available actions for the issue

IssueWorkflowManager issueWorkflowManager = ComponentAccessor
.getComponentOfType(IssueWorkflowManager.class);

Collection<ActionDescriptor> actions = issueWorkflowManager
                .getAvailableActions(issue);

Thanks , I am able to get the name. But to get available issue i am getting several errors.

Also now i want to set status of the current issue to some status like closed, so how can i do that?

what is the error messages you are getting?

The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issueWorkflowManager for class: com.onresolve.jira.groovy.Script149

how you are getting issueWorkflowManager ?

i have updated answer check now

Also i need to set status of current issue, say from X to Y, how can i do that?

For previous example, I have defined def issueWorkflowManager, but still its throwing error.

Thanks a lot, I got it now, now i am able to get all the status.

now i want to set status, such that i jump to that status on transition, So i have written this peice of code, but i guess its not working , So can you help me out with this?

/*

workflowTransitionUtil.setIssue(it);
workflowTransitionUtil.setAction (5)

*/

is there any mandatory fields on that transitions?

Remember - you can NOT just "set a status".

Status is NOT a field, it is an indicator of where the issue is in the workflow. To change status, you MUST move the issue through transitions to the new status.

The only time you can "set" a status without transition is when you are adding issues to Jira.

When I am setting Action ID (20) for eg. I am getting switched to that transition but status remains the same. So what can be wrong?

@ rambanam : Yes there are mandatory fields like time and Comment.

@Nic Brough : But i can change the transition rgt? & when transition is done the status gets updated rgt?

@akash, don't forgot to voteup/like/accept as answers if anything helped to you

@Nic Brough : Now what if i want to move from A to C, auto Transition to C . For some time i don't want status B. I know th eobvious answer would be o create transition but i need to do it in groovy way.

>But i can change the transition rgt?

To try to clarify: You can NOT "change the transition". A transition moves an issue through the workflow. To change the status of an issue, you MUST use a transtion that goes from your old status to the new status.

> & when transition is done the status gets updated rgt?

Correct, because the whole point of a transition is that it changes the status.

No. You are not grasping this.

To change a status, you must use a transition

You cannot get around this. Groovy can tell Jira to do these transtitions. You can detect and automate them. You can protect them so that only certain users or automation can perform them and no-one else sees them.

But. You must have a transtion from A to C if you want to change status from A to C.

Unless you're happy to go from A to B to C, in which case you need transitions from A to B and from B to C.

It's not "the obvious answer", it is the "only answer". You must have that transition.

Yes, I have a transition from A -> B and from B-> C, So now can you tell me the way to do transition.

hi 

can we print the version detail of current issue into a text file  by using groovy script ?

please help me

Thanks & regards 

Naidu .l 

Please see the answer to your previous question at https://answers.atlassian.com/questions/46798458

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

352 views 0 6
Read article

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