Forums

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

Set issue reporter via groovy script

Hans-Hermann Hunfeld
Contributor
January 4, 2017

Hi folks,

maybe a stupid question, but i don´t find what i´m doing wrong here:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
issue.reporterId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

This is a groovy scripted post function to change a cloned issues´ reporter to the current user (instead of the reporter of the to be cloned issue), after changing from componentManager to ComponentAccessor this is in general working.

But, while testing it it looks a bit weird:

image2017-1-4 18:22:58.png

You see, the assignee was cloned and the correct name was set, but the reporter was somehow changed to the username instead. Tried to find a solution by myself but without success... sad

 

Many thanks!

1 answer

1 accepted

5 votes
Answer accepted
adammarkham
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.
January 4, 2017

Your assigning an com.atlassian.jira.user.ApplicationUser object in JIRA 7 or a com.atlassian.crowd.embedded.api.User object in JIRA 6 to the reported id. 

The reported id should be the username. So you need:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
issue.reporterId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
Hans-Hermann Hunfeld
Contributor
January 4, 2017

Hi Adam,

thanks, is working as expected! Seems that i "only" missed the ...getLoggedInUser().name

Just for other users, this was tested with JIRA 7.1.7 and ScriptRunner 4.3.13...

AccessHolding July 4, 2018

Hi Adam,

Is this approach still valid?

I have an if condition to set the issue reporter which throws null as soon as I try your method.

...

def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ASD: On behalf of")
def newReporter = issue.getCustomFieldValue(customField) as ApplicationUser

if (customField != null){
    issue.setReporter(newReporter)
} else {
    issue.ReporterId = currentAppUser
}

...

The if tree is fine but I never reach the else tree. Even if the customField is not even set.

Any idea?

Best,

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events