Forums

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

Change user when firing event through groovy script

bschmi
Contributor
June 16, 2018

Hi!

I'm using the following Groovy Code through a Script Listener what perfectly does the Job. 

Long EVENT_ID = new Long("10300")
ApplicationUser currentUser
IssueEventBundle eventBundle

JiraAuthenticationContext jiraAuthContext = ComponentAccessor.getJiraAuthenticationContext()
IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)

currentUser = jiraAuthContext.getUser()
eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, currentUser, EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)

 Basically the Code triggers an email in the end and my only remaining requirement is that the email's Sender is NOT the current logged in user (current state with implementation).

The email's Sender should be "Helpdesk", therefore I even created an user "Helpdesk" with appropriate application Access and even assigned a valid mail address to it but when the mail is send by the Code above the Sender is still the currently logged in user.

I tried to Change the ApplicationUser currentUser line but to no avail.

I appreciate any hint. Thanks in advance!

Best regards,

Birgit

 

 

1 answer

1 accepted

0 votes
Answer accepted
Suhas P
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 16, 2018

Have you tried UserManager Class? It has "getUserByName" method which gives ApplicationUser object.

def userManager = ComponentAccessor.getUserManager()

ApplicationUser helpDeskUser = userManager.getUserByName("helpdeskUsername")

Then you can user helpDeskUser instead of 'currentUser' in your script.

Daniel Ebers
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 16, 2018

That worked out perfectly for our use case also. Many thanks!

Suggest an answer

Log in or Sign up to answer