How to change creator system field via JAVA API?

david kreuter August 19, 2015

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

3 votes
Answer accepted
Manuel Lindner January 16, 2017

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.

1 vote
GabrielleJ
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.
August 20, 2015

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.

 

david kreuter August 20, 2015

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

0 votes
Deleted user January 16, 2017

@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

 

0 votes
Tim Eddelbüttel
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 12, 2017

@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 

Suggest an answer

Log in or Sign up to answer