Groovy : update issue reporter with are particular user

I have a user given to me via a request from and I want to use groovy to update the report. I worked out how to locate the user object from searching the user's ID number. (Jira links into our companies Active Directory).

 

def userName = "U00001"
	def userObject = ComponentAccessor.getUserManager().getUserByName(userName)
	

The object consists of these elements:

 

 

2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: key = u00001
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: directoryId = 10000
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: directoryUser = U00001:10000
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: emailAddress = Samuel.SURNAME@company.com.au
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: username = U00001
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: name = U00001
2017-04-11 12:29:29,737 WARN [runner.ScriptRunnerImpl]: displayName = SURNAME, Samuel

 

Now I can't work out how to set the reporter to this user object.

I have tried this code but it just update's the field and I can see jira does not see it as a user. It's just text sitting in the report field. 

issue.reporterId = userObject.displayName
issue.store()

I took this idea from this post. I tried the same method in the answer and set the current logged in user as the repoter, but jira still doesn't see it as a user object.

issue.reporterId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
issue.store()

https://community.atlassian.com/t5/JIRA-questions/Set-issue-reporter-via-groovy-script/qaq-p/422498

 

1 answer

Just worked it out. This may be unique to my situation as my Jira is integrated with Active Directory.

I used .key

def userName = "U000001"
def userObject = ComponentAccessor.getUserManager().getUserByName(userName)
issue.reporterId = userObject.key
issue.store()

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

134 views 4 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you