Forums

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

How to get user for ScriptRunner listener event?

alexmears
Contributor
July 21, 2019

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

1 vote
Matias Stachowski
Contributor
July 22, 2019

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
alexmears
Contributor
July 22, 2019

Thank you, @Matias Stachowski

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

Matias Stachowski
Contributor
July 23, 2019

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

francis
Atlassian Partner
September 18, 2019

@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...

alexmears
Contributor
October 15, 2019

@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