How to change creator system field via JAVA API?

Is there any way to change the "creator" system field using the JIRA JAVA API. The background: the user should be able to create an issue which should be visible as anonymous within the system. So the reporter field can be easily changed during creation to some technical user called "anonymous", but still the "creator" field is set to the current user, who created the issue and this information is visible in the change history.

So one approach would be to change the creator within a post-function, e.g. script-runner, but how?  

4 answers

1 accepted

This widget could not be displayed.

Hi!

A solution for changing the Creator field during issue creation would be to switch the AuthenticationContext to the anonymous user within a post-function. This can be implemented by using ScriptRunner and a Custom script post-function with the following code:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("<anonymous_username>")
def authContext = ComponentAccessor.getJiraAuthenticationContext()

authContext.setLoggedInUser(user)

 

It is very important that this post-function must be executed before the post-function (named: "Creates the issue originally.") which creates the issue.

This widget could not be displayed.

These can be done in 2 ways:

  • Post-function - This will have to be added in the "Create" transition of the ticket (Edit the Workflow and click on the Create label). Put a post-function in to update the Assignee to someone.
  • Default Assignee - I'm not sure if you have checked this, who is the default assignee for your project? This can be set in the "Roles" admin screen of your project.

 

hi gabrielle, what I need is to update the creator field to a technical user, the creator system field is not equal to the assignee. I understand completely your approaches and they are absolutely fine, but does not macht my use case. The creator field is not visible on the GUI, just in the change history of an issue. BTW, is also not the reporter. See: https://answers.atlassian.com/questions/307400/creator-field

This widget could not be displayed.

@david kreuter: Did you find a solution for this?

I think i will create a hidden transition and trigger this with JIRA Automation as another user. I think this will work. Also for the created issue link.

Regards,
Tim 

This widget could not be displayed.

@Tim Eddelbuettel There are multiple solutions to this:

  1. A create postfuntion that sets the new reporter to an "anonymous" user and deletes the whole issue history (which is only the change from the original reporter) -> needs scriptrunner
    https://docs.atlassian.com/jira/7.0.6/com/atlassian/jira/issue/changehistory/ChangeHistoryManager.html#removeAllChangeItems-com.atlassian.jira.issue.Issue-
  2. A create postfunction that clones the issue with an anonymous placeholder reporter (again scriptrunner) and uses this anonymous user as the one who creates the ticket
  3. A custom implementation for issue creation which creates an issue through a rest call, authenticating the call as the anonymous placeholder user (probably alot of work, but needs no scriptrunner)

We have used 2) as for our needs it was the best solution.

Greetings, alex

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

84 views 0 1
Join discussion

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