How do I anonymize issue creation in post function via scriptrunner

How can I assign a default user when creating a new issue so that the history log displays "<default user> created issue"

  1. I should have stated my question more clearly. How do I programatically assign the currentUser to a predetermined user ( "defaultReporter" for example ) to really anonymize ticket creation when a logged in user creates a new issue. I am using scriptrunner and a post function/custom script in the create transition.

    I can assign a default reporter, but the current user is still visable in the History or All tab of the issue. There it is documented who actually created the ticket. I need the functionallity to work for logged in users.

    Thanks..

2 answers

1 accepted

0 votes
Accepted answer

Actually I was able to resolve the issue myself with the following code..

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
def us = ComponentAccessor.getUserUtil().getUserByName("Anonymous").getDirectoryUser();
def ac = ComponentAccessor.getJiraAuthenticationContext();
ac.setLoggedInUser(us);
issue.setReporter(us);

and it functions fine in the Create Issue transition, it is actually the first script to be called in the post functions. The assignment of LoggedInUser solved the issue of creator anonymity in the tabs History and All.

That means you have a real user called Anonymous... that's not quite the same.

Actually I have to agree...went back and found the method clearLoggedInUser() in JiraAuthenticationContext which I had missed before. I have now just left the Reporter as optional and then set as hidden, in the post function I now just call ac.clearLoggedInUser() and the issue is then actually anonymous.

Thanks for the comment, got me to go back and check again...you could have just pointed out the clearLoggedInUser() method though.

I probably would have, but I thought you were happy with your solution. If you want tips, it seems like you use a try/finally block, and replace the actual logged in user. Otherwise I think this user would require to log in again.

Actually the user remains logged in. Also even if I am happy with the solution..I am even happier to find a more correct solution or other options. Also it is helpful for others searching for solutions if an expert points out short-commings or suggests other solutions..so Please comment when you can! Thanks again!

Find an add-on that can create a JIRA Issue OR will allow you to run a script that will create the JIRA issue then just use the default assignee as the reporter.

I should have stated my question more clearly. How do I programatically assign the currentUser to a predetermined user ( "defaultReporter" for example ) to really anonymize ticket creation when a logged in user creates a new issue. I am using scriptrunner and a post function/custom script in the create transition.

I can assign a default reporter, but the current user is still visable in the History or All tab of the issue. There it is documented who actually created the ticket. I need the functionallity to work for logged in users.

Thanks..

This means that the Post-function you have put will be ran after the ticket has been created. What you need to do here is to create the ticket not via the post-function. The ticket must be created outside the post-function. You cannot even put your post-function before the "Create the issue" because there's nothing to update if you put that after anything else.

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

463 views 2 5
View question

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