Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script Listener only works for Generic Event - Auto Asisgning Component Lead

Sidh Regmi June 25, 2018

Below script works only under 'All Events' or 'Generic Event'. I have set it to 'Issue Commented', and 'Issue Updated' without any luck. 

Only works during workflow events. I haven't set it to any workflows though. It probably only works because of the 'Generic Event' that is fired from the workflow transitions.  Do I need to update the script to work with other events? like edit issues, commented etc. 

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def componentManager = ComponentAccessor.getProjectComponentManager()

def componentLead = userManager.getUserByKey(componentManager.findComponentsByIssue(issue)[0].getLead());
log.info(componentLead);
issue.setAssignee(componentLead)

 

1 answer

0 votes
Mark Markov
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.
June 25, 2018

Hello @Sidh Regmi

And welcome to the community :)

The thing is that whenever you update or comment issue during transition, all these actions attached to the event that fires in this transition.

So if you need to catch changes in specific transition, you need to fire specific event, that you ll be catch in your listener.

Sidh Regmi June 25, 2018

Thanks Mark ! 

I am actually trying to run this when an issue is edited. Meaning this is for when components field is edited. Shouldn't the 'Issue Updated' event be triggered when editing a field? 

I am using the script in 'Custom script listeners'

Mark Markov
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.
June 25, 2018

Yes, when you re edit issue, Issue Updated will be trigger.

And to catch changes you need code like this:

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Component"}

if (change) {
    log.debug "Value changed from ${change.oldstring} to ${change.newstring}"
 // your actions if the field has changed
}

change.newstring contains new value

Suggest an answer

Log in or Sign up to answer