is there any way to get the Automated transitioned trigger details from Issue getChangeHistoryManager?

Hi,

Simillar to the below script runner sample(i,e Date of First Transition), is it possible to get the automated transitioned trigger(i,e user/source i,e kodbuild made commit 202 or Vivek Abraham started review - trigered the transition information) mainly ::

My issue History tab looks as below::

 Automated transition triggered when Vivek Abraham started review KDGPROJECT-128 in 10 - 12/Jul/16 6:27 PM   
StatusIn Progress [ 3 ]CODE REVIEW IN PROGRESS [ 10300 ]

 

Automated transition triggered when kodbuild made commit 202 in 10 - 13/Jul/16 9:49 PM  
StatusCODE REVIEW COMPLETED [ 10301 ]Done [ 10001 ]

 

package com.onresolve.jira.groovy.test.scriptfields.scriptsimport com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager() changeHistoryManager.getChangeItemsForField(issue, "status").find {     it.toString == "In Progress" }?.getCreated()

Please share your feedback/inputs...

-Manju

1 answer

1 accepted

2 votes

Its possible to get those descriptions using the HistoryMetadataManager.

The following example should show you how to get this description for when Stash/Bitbucket transitions the issue to "In Review" when a pull request is created:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.changehistory.metadata.HistoryMetadataManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def historyMetadataManager = ComponentAccessor.getComponent(HistoryMetadataManager)
List<ChangeHistory> allChangeHistories = changeHistoryManager.getChangeHistoriesForUser(issue, currentUser)

def relevantChangeHistory = allChangeHistories.find { changeHistory ->
    changeHistory.getChangeItemBeans()*.toString.contains("In Review")
}
def historyMetadata = historyMetadataManager.getHistoryMetadata(relevantChangeHistory, currentUser)
historyMetadata.getHistoryMetadata()?.description

It will show something like: (Automated transition triggered by pull request #348 in Stash)

It should work the same for other type of automated transitions.

Thanks for your prompt feedback Adam !

It really helping me to identify whether a JIRA issue transition is triggered manually by assignee or automatically from sub-version or crucible app links configured in my workflow.

But When a transition is triggered automatically, it ignores any conditions, validators or permissions configured on the transition - is there any way to handle the conditions/validations before the automatic transition becomes successful based on condition result(PASS or Fail)? 

The transition would be controlled by whatever plugin does the auto-transition, so you would need to ask whoever that is (there may be an option to not skip these).

It sounds like when they perform the transition automatically they skip permissions, validators and conditions. Theres not much we can do from ScriptRunner if this is what they are doing.

This plug in is from Jira, They said at the moment, this is not possible to achieve in JIRA. This is not something we can set in the configuration and we have a feature request raised on this JSW-14579. Thanks again for your response !

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

113 views 0 3
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