Groovy : update issue reporter with are particular user

meddows April 10, 2017

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

1 vote
meddows April 10, 2017

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
TAGS
AUG Leaders

Atlassian Community Events