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

How to get user for ScriptRunner listener event? Edited

Currently

I have ScripterRunner Cloud Listeners setup for Issue Updated, IssueLink created / deleted events.

Problem

I want to get the User that triggered these events, as I want to use the User to trigger new events.

 

e.g. issue = issue, event = event

But there is no "user" or "event.user"

1 answer

I didn't work with Scriptrunner in Jira Cloud, but I know that on server you can get the change history with the ChangeHistoryManager and find out who the "author" of the change is.

So something like this could be an idea:

List<ChangeHistory> changes = ComponentAccessor.getChangeHistoryManager().getChangeHistories(event.issue);
ApplicationUser latestUser = changes.get(changes.size()-1).getAuthorObject();

 

If you can't use those things in scriptrunner, you'll have to get the issue changelog through the rest api and find the author of the latest change. (It's sorted by date starting from the oldest)

/rest/api/3/issue/{issueIdOrKey}/changelog

Thank you, @Matias Stachowski

This solution unfortunately does not work (or I am unable to get working) on ScriptRunner for Jira Cloud.

Which part is not working? Did you try using the REST Api to get the last change in the changelog too?

@alexmears Did you ever found a solution. 

We tried to implement an approach where an issue is updated under certain conditions, but that update triggered a new update event, which got processed again.

So the listener is not usable...

@francis  ,

I got it working as well as we needed with:

if (changelog != null) {
if (binding.hasVariable('user')) {
println("initiating user = " + user.name)
} else {
println("initiating user is unknown")
}
};  

Some events don't have a changelog, so we aren't getting the user for those.

Like # people like this

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

365 views 1 3
Join discussion

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