Forums

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

Changing the create issue user before creating the issue via email handler

Ivelin Ognyanov May 28, 2018

Hello everyone,

 

Can you help me with a simple script in post functions section in the workflow? I hit a bug that when issues are created via email, I got in the history tab wrong user for the one who creates the issue:

 

"user_name created issue - date."

 

The problem is that this user doesn't have anything to do with the issue, no access, no nothing.

 

I found this and it describes exactly the issue I have: https://jira.atlassian.com/browse/JRASERVER-41322

Sadly, the discussion there ends up with "contact support" solution and that one expired for me.

So I started to search how to change the user name of the creator before the creation of the issue. Found this one: 

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("<anonymous_username>")
def authContext = ComponentAccessor.getJiraAuthenticationContext()

authContext.setLoggedInUser(user)

From: https://community.atlassian.com/t5/Jira-questions/How-to-change-creator-system-field-via-JAVA-API/qaq-p/239871

 

The thing is that it doesn't work, I change the user name with the desired one, preserving the :

("< >")

Nothing changes, still the created issue is from a wrong user name. The script is created in that way: post functions -> add post function -> script post-function -> inline script -> ran before "Creates the issue originally." as instructed in the thread I found.

 

I am running jira 6.2.7 server edition. Will appreciate any help as I am sure the stupid one here is me. :)

 

Best Regards,

1 answer

1 accepted

1 vote
Answer accepted
Alexey Matveev
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.
May 28, 2018

Try to add to the end of your script:

ComponentAccessor.getIssueManager().updateIssue(userwitheditpermissions, issue, EventDispatchOption.ISSUE_UPDATED, false)
Ivelin Ognyanov May 28, 2018

Thanks a ton for the answer.

Sadly, there is no change with the added line. The user name is still a wrong one.

The script right now:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("<ivelin.ognyanov>")
def authContext = ComponentAccessor.getJiraAuthenticationContext()

authContext.setLoggedInUser(user)
ComponentAccessor.getIssueManager().updateIssue(userwitheditpermissions, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

Best Regards, 

Alexey Matveev
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.
May 28, 2018

I can not see how you set value for the userwitheditpermissions variable

Ivelin Ognyanov May 28, 2018

Can you explain with a little bit of a more details? I am kinda new to scripting/java/jira. The whole jira thing was transferred to me recently and I am still kinda learning, otherwise I am just a normal "dumb" windows sys admin without any experience with the above. :)

Alexey Matveev
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.
May 28, 2018

Ok, try like this. If it does not work have a look at the atlassian-jira.log file for errors.

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("ivelin.ognyanov")
def authContext = ComponentAccessor.getJiraAuthenticationContext()

authContext.setLoggedInUser(user)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Ivelin Ognyanov May 28, 2018

It worked! Thanks a lot for your time and help, appreciated! :)

Suggest an answer

Log in or Sign up to answer