How to get transition name using script listener?

Teja
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.
October 11, 2022

Hi Team,

I would like to know how we get the workflow transition name,

I am trying to update the custom field when workflow transition action is performed.

def eventTypeManager = ComponentAccessor.getEventTypeManager()

def eventTypeName = eventTypeManager.getEventType(event.eventTypeId).getName()

log.info('Event Type Name:' + eventTypeName)

if(eventTypeName == 'Generic Event' && transitionName == 'Refresh')

{

//Update custom field value

}

else{

exit

}

Thanks

1 answer

0 votes
robert Mugabuhamye
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.
October 11, 2022

hello @Teja ,

You could use the transition id. If the name of the transition change, the Id won't.

You can easily find the Id of you transition by going in workflow edition mode: 
Screenshot 2022-10-11 093955.png

Teja
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.
October 11, 2022

@robert Mugabuhamye 

Thanks for your reply!

I am having a hard time getting the code for the transition ID, any idea?

robert Mugabuhamye
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.
October 11, 2022

@Teja what do you mean by "having a hard time " ?

Teja
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.
October 11, 2022

Hi @robert Mugabuhamye 

I tried the below code, it works for all the transitions, I want this to run on a particular actionId is 591

 

def eventTypeManager = ComponentAccessor.getEventTypeManager()
def eventTypeName = eventTypeManager.getEventType(event.eventTypeId).getName()
log.info('Event Type Name:' + eventTypeName)

def actionId = 591
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueInputParameters = issueService.newIssueInputParameters()
def validationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters)

if(eventTypeName == 'Generic Event' && validationResult)

{

//update

}
robert Mugabuhamye
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.
October 11, 2022

@Teja ,

The solution in that case would be :

  1. use a scripted post function 
    1. with this solution, no need to used the transition Id
  2. or get the transientVars to compare to your ID 
Like Teja likes this
Teja
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.
October 11, 2022

Yep I have been trying the solution of getting transientVars, but could not able to resolve No such property: transientVars for class

def eventTypeManager = ComponentAccessor.getEventTypeManager()
def eventTypeName = eventTypeManager.getEventType(event.eventTypeId).getName()
log.info('Event Type Name:' + eventTypeName)

int
actionId = 591
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()

if(eventTypeName == 'Generic Event' && actionName == "Refresh")

{
//update
}  

 

 Error

groovy.lang.MissingPropertyException: No such property: transientVars for class: Script63

 

Suggest an answer

Log in or Sign up to answer