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

Error creating JIRA tickets via groovy script set up as a service

I'm trying to set up a groovy service in JIRA to read a CSV file and create tickets based on values in that. When I run the script manually through the script console, it works as expected. When I set up the service, it doesn't create the tickets and gives the below error.

Error creating issue at 1: Errors: {pid=Anonymous users do not have permission to create issues in this project. Please try logging in first.}
Error Messages: []

My guess is that running this from the script console uses the currently user logged in (myself) which it can't reference while running as a service. This would be why it works from the script console and not as a service.

Below is the snippet of code that is actually doing the creation. While I didn't include it in the code block, assume that issueInput object is a valid IssueInputParameters. If there is anything relevant that is missing from the snippet of code that would be helpful for troubleshooting, let me know and I can fill in any blanks. I figured the entire script might not be necessary since it works just fine from the script console.

ApplicationUser user = ComponentAccessor.UserManager.getUserByName("admin")
 
IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInput)

if (createValidationResult.isValid()) {
	IssueService.IssueResult issueResult = issueService.create(user, createValidationResult)
} else {
	log.error("Error creating issue at " + rowCount + ": " + createValidationResult.getErrorCollection())
}

Based on the requirements I have, it is not an acceptable solution to allow anyone to create issues in the project.

What changes needs to be made, either to the script or otherwise, to allow this service to create issues in the project?

3 answers

1 accepted

3 votes
Answer accepted

yeah that rings a bell. Try setting the logged in user at the top:

ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(...)

The first line doesn't look correct. I think you want:

ComponentAccessor.userManager.getUserByName("admin")

see https://scriptrunner.adaptavist.com/latest/jira/recipes/jelly-migration.html#_in_code

 

You are correct that there was a typo on the first line. Correcting that did not resolve the error that I'm getting though.

I looked through the linked page again and also tried changing it up to get the current logged in user instead of a user provided by me. This would be similar to the create issue script on that page. When running though, it appears that the user gets set to a null value.

There is no current logged in user in a service. Even if you run it manually.

Can you add some logging so you can see at what point it gets set to a null value.

The NPE was when I tried to log the username of the current logged in user when the service was running. It would be expected to be null since there is no current logged in user.

I put some logging in right before I call the IssueService.validateCreate() method to output the username of the user object I have in the script. It outputs:

Import CSV Service [c.c.jira.csv.CSVImport] Username of user object is: admin

According to the API docs at https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/bc/issue/IssueService.html#validateCreate(com.atlassian.jira.user.ApplicationUser,%20com.atlassian.jira.issue.IssueInputParameters), it would use the user I'm passing it, but it seems to be ignoring it.

That did the trick. Could you convert that comment to an answer for me to mark as accepted? I feel like that would best to show others that might get here what the solution to this specific problem was.

Hi @Adam Yerkman ,

Could  you please share complete script for this ?

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