Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to set assignee and reporter on an issue created via ScriptRunner Programatically

Hi 

I am using following code to set the reporter of the issue that is being created

def issueInputParameters = issueService.newIssueInputParameters().with {
setIssueTypeId(currentIssueType.id)
setReporterId((ComponentAccessor.userManager.getUserByName("ReporterName") ).key)
setSummary(summary)
setPriorityId((constantsManager.priorities.findByName(priorityName) ?: constantsManager.defaultPriority).id)
}

 

Issue gets created correctly, however I have noticed that the "Reporter" and "Assignee" both are set to admin which is the user that executes the automation rule.

Question: How do I get the "ReporterName" assigned to the Reporter jira attribute.

Also, how do the set the assignee as well in the IssueInputParameters?

 

Thanks in advance.

 

1 answer

1 accepted

1 vote
Answer accepted

Hi,

I use this to set the reporter

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
log.warn(loggedInUser.name)

issueInputParameters        
.setProjectId(project.id)        
.setIssueTypeId("10001")        
.setReporterId(loggedInUser.name)

 I think is the same thing for the assignee. Make sure you do not have a automation rule that overwrite assignee and reporter field

Hi Mohamed,

 

Thank you for your response.

I tried your suggestion but still it is setting the admin user.

My code is as follows

===================================================

def validationResult;
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(loggedInUser) ;

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectName);
def projectComponentManager = ComponentAccessor.getProjectComponentManager();
def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager

def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId((taskType == "Primary") ? project.id : parentIssue.projectObject.id)
setIssueTypeId(currentIssueType.id)
setReporterId(loggedInUser.name)
setSummary(summary)
setPriorityId((constantsManager.priorities.findByName(priorityName) ?: constantsManager.defaultPriority).id)
}

validationResult = (taskType == "Primary") ? issueService.validateCreate(loggedInUser, issueInputParameters) :
issueService.validateSubTaskCreate(loggedInUser, parentIssue.id, issueInputParameters);

def issueResult = issueService.create(loggedInUser, validationResult);

===================================================

Admin user is the one that is executing the automation rule and hence it is setting the same user as Reporter and Assignee.

LoggedInUser is not the admin user.  

In fact, I am creating primary and sub task from a CSV file which contains the reporter and assignee value.

What I want to achieve is that if the Reporter does not exists then set to "Anonymous"

and similary Assignee to "Unassigned"

Hi @Abdul ,

Based on the script, it seems there are more script above that set the loggedInUser

Alternatively, you can set and get the desired reporter or assignee manually. For example, declare another line to get the user information of the desired reporter or assignee.

import com.atlassian.jira.user.ApplicationUser

//get the desired reporter and assignee user information
ApplicationUser reporter = ComponentAccessor.getUserManager().getUserByName("kim") //eg: username is kim

ApplicationUser assignee = ComponentAccessor.getUserManager().getUserByName("loong") //eg: username is loong

...

//set the reporter and assignee

setReporterId(reporter.id)

setAssigneeId(assignee.id)

If the reporter value is returning a null basically setting Anonymous to the issue reporter. You may also verify the project is allowing Anonymous issue creation, see JIRAKB - How to allow users to create issues anonymously.

I hope this helps.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you