How to get Issue Status using groovy

AKASHB July 11, 2013

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?

2 answers

4 votes
RambanamP
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.
July 11, 2013

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);

AKASHB July 11, 2013

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?

RambanamP
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.
July 11, 2013

what is the error messages you are getting?

AKASHB July 11, 2013

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

RambanamP
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.
July 11, 2013

how you are getting issueWorkflowManager ?

i have updated answer check now

AKASHB July 11, 2013

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.

AKASHB July 11, 2013

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

AKASHB July 11, 2013

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)

*/

RambanamP
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.
July 11, 2013

is there any mandatory fields on that transitions?

Nic Brough -Adaptavist-
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, 2013

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.

AKASHB July 11, 2013

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?

AKASHB July 11, 2013

@ 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?

RambanamP
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.
July 11, 2013
RambanamP
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.
July 11, 2013

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

AKASHB July 11, 2013

@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.

Nic Brough -Adaptavist-
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, 2013

>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.

Nic Brough -Adaptavist-
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, 2013

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.

Like Gary Bates likes this
AKASHB July 11, 2013

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

Naidu Lothugedda January 29, 2017

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 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2017

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

3 votes
Amar Parthasarathy October 12, 2018

Deprecated : 

issue.getStatusObject().getName();

 

The following will work: [as of Oct 2018]

  issue.getStatus().name

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events