Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

transition issue on field update

How to transition an issue to a specified status on update of its custom fields?

Currently I implemented a Listener which transitions the ticket when it receives an Update event but realized there's a criticality in Jira's implementation whereby the issue might be in an inconsistent state just after having been updated and the transition fail, the result is that Jira returns an:

"It seems that you have tried to perform a workflow operation (some-transition) that is not valid for the current state of this issue"

Of course the transition is valid instead.

Someone suggested setting the workflow states which are null or 0 to "ACTIVATED" manually through the following code:

List<GenericValue> workflowEntries = ComponentAccessor.getOfBizDelegator().findByAnd("OSWorkflowEntry", FieldMap.build("id", issue.getWorkflowId()))
for (GenericValue workflowEntry : workflowEntries)
{
if (workflowEntry.getInteger("state") == null || "0".equals(workflowEntry.getInteger("state").toString()))
{
workflowEntry.set("state", new Integer(WorkflowEntry.ACTIVATED))
workflowEntry.store()
}
}

However this solution doesn't seem to work in this case.

What is the correct way to implement an automatic transition when a field is updated by the user?

 

1 answer

0 votes
Antoine Berry Community Leader Jul 03, 2019

Hi @Beppe Marcon ,

I have been using something like this in the beginning of the script : 

def workflowEntries = ComponentAccessor.getOfBizDelegator().findByAnd("OSWorkflowEntry", FieldMap.build("id", issue.getWorkflowId())) // get workflow informations
def workflowState = workflowEntries[0].get("state")
def tryCounter = 0

while(workflowState==0) {
log.debug("Retry number " + tryCounter)
sleep(1000)
workflowEntries = ComponentAccessor.getOfBizDelegator().findByAnd("OSWorkflowEntry", FieldMap.build("id", issue.getWorkflowId()))
workflowState = workflowEntries[0].get("state")
log.debug("workflowState="+workflowState)
tryCounter++
if (tryCounter == 5) {
log.error("Too many retries...")
break
}
}
log.debug("now proceeding with the workflow transition...")

But I only have had issues in a create listener.

My guess is that you are trying to trigger a transition that cannot be executed in the current status. Are you sure you are triggering a valid transition ?

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

161 views 1 1
View question

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you