Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
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

Change the reporter of an issue to a different user via Scriptrunner as a post function

Hi

I am new to Scriptrunner but we have it as a plugin and I want to change the reporter of an issue to another user via a post function in the workflow. Could someone supply working groovy script for Jira 8.7?

 

Thanks

 

Gordon

4 answers

1 accepted

0 votes
Answer accepted

Thank you Fabio that is working perfectly for me and I really appreciate your time on this.

Could I just ask if I wanted to combine your code with my code below which is to create a sub task and amend the name and assign it to a user, what would that look like?

 

Thanks again 

 

Gordon

 

script 2.PNG

I'm happy that it worked. Please could you specify if you need to create the subtask in the same postfunction that update the reporter.

And please accept my answer and not yours :)

Ciao,

Fabio

Apologies re the accepted answer! Hopefully correct now. My eyes are not what they used to be! Yes correct - same post function.

Thanks again

Gordon

0 votes

Hi @Gordon Rutherford ,

 

try this code :

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;

IssueManager issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getUserManager();

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ApplicationUser reporter = userManager.getUserByKey("YOUR_REPORTER_KEY_HERE");

issue.setReporter(reporter);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

I don't know if the reporter to set is within the source issue in another Field. BTW, this code should help you.

Fabio

Hi Fabio

I appreciate your input!

I realise I should have brought more detail - there are two use cases for this script - one when an issue is created (not updated) and perhaps that is causing this error shown in snip image shown below when I inserted it in that post function?

 

script error.PNG

The other is changing a subtask reporter when the sub task is created by scriptrunner with this additional issue action which I want to add to with also the 'change of reporter'

issue.summary = 'Add Chan PD Image Request: ' + sourceIssue.summary
import com.atlassian.jira.component.ComponentAccessor

// the username of the assignee
final String userName = "q1424781"

def user = ComponentAccessor.userManager.getUserByName(userName)
issue.setAssignee(user)

 

 

Thanks for your help with this!

 

Best regards

 

Gordon

HI @Gordon Rutherford ,

 

here the code updated (the problem was that EventDispatchOption was not imported).

Please move this post function after issue creation.

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.event.type.EventDispatchOption;

IssueManager issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getUserManager();

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ApplicationUser reporter = userManager.getUserByKey("YOUR_REPORTER_KEY_HERE");

issue.setReporter(reporter);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

Moreover, in order to set the reporter use the method issue.setReporter(user) as per Assignee.

Hope this helps,

Fabio

Hi Fabio

Thanks for your response! So I have inserted the new code after 'Create' in the post function order as shown below where 'q1454625' is the 'new' reporter I want for the issue. This however does not update in the created issue - Reporter shows as 'anonymous'.

Sorry if I am missing something as I also didn't understand you last comment: 

'Moreover, in order to set the reporter use the method issue.setReporter(user) as per Assignee.' Does that mean I need to add some extra code to the script shown below to make it work and update the Reporter?

 

Thanks again for your help

 

Best regards

 

Gordon

script.PNG

Hi @Gordon Rutherford ,

the problem was during finding user process. I fised this issue. Please try this code :

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.event.type.EventDispatchOption;

IssueManager issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getUserManager();

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ApplicationUser reporter = userManager.getUserByName("YOUR_REPORTER_KEY_HERE");

issue.setReporter(reporter);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
Like Gordon Rutherford likes this
0 votes

Hi @Gordon Rutherford ,

 

try this code :

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.config.IssueTypeManager;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.issue.MutableIssue;

IssueManager issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getUserManager();
IssueTypeManager issueTypeManager = ComponentAccessor.getComponentOfType(IssueTypeManager.class);
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ApplicationUser reporter = userManager.getUserByKey("YOUR_REPORTER_KEY_HERE");

issue.setReporter(reporter);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

Project project = issue.getProjectObject();
IssueType subTaskIssueType = issueTypeManager.getIssueType("YOUR_SUBTASK_ISSUE_TYPE_NAME_HERE");
MutableIssue mIssue = issueFactory.getIssue();
mIssue.setProjectObject(project);
mIssue.setIssueTypeObject(subTaskIssueType);
mIssue.setParentObject(issue);
mIssue.setSummary("Edit Promo: "+issue.getSummary());
mIssue.setReporter(reporter);
mIssue.setAssignee(reporter);
issueManager.createIssueObject(user, mIssue);

 

Please let me know if it works for you and, please, click on Accept Answer on this answer :)

Ciao,

Fabio

Hi Fabio

Only just came back to try this now so apologies for the delay - I get the error below on the line where I have entered the name of the sub task

Regards

 

Gordon

 

fabio 1.PNG

0 votes

Hi @Gordon Rutherford ,

try this code, I missed import of IssueType class :

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.config.IssueTypeManager;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.issuetype.IssueType;

IssueManager issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getUserManager();
IssueTypeManager issueTypeManager = ComponentAccessor.getComponentOfType(IssueTypeManager.class);
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ApplicationUser reporter = userManager.getUserByKey("YOUR_REPORTER_KEY_HERE");

issue.setReporter(reporter);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

Project project = issue.getProjectObject();
IssueType subTaskIssueType = issueTypeManager.getIssueType("YOUR_SUBTASK_ISSUE_TYPE_NAME_HERE");
MutableIssue mIssue = issueFactory.getIssue();
mIssue.setProjectObject(project);
mIssue.setIssueTypeObject(subTaskIssueType);
mIssue.setParentObject(issue);
mIssue.setSummary("Edit Promo: "+issue.getSummary());
mIssue.setReporter(reporter);
mIssue.setAssignee(reporter);
issueManager.createIssueObject(user, mIssue);

Hi Fabio

Sorry I have only just had a chance to test and it fails

Here is the log from Jira - do you need anything else to diagnose?

Regards

Gordon

 

2021-03-17 16:47:40,394 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue COR-50 for user 'Gordon.Rutherford'. View here: http://jira.uk.broadcast.qvc:8080/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=POM%2FSOM%2FDOM&descriptorTab=postfunctions&workflowTransition=1&highlight=2
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException: null value in entry: issue=null
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2050)
at com.google.common.cache.LocalCache.get(LocalCache.java:3952)
at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4871)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.getValuesForIssueId(EagerLoadingOfBizCustomFieldPersister.java:103)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.getValuesForTypeAndParent(EagerLoadingOfBizCustomFieldPersister.java:86)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.updateValues(OfBizCustomFieldValuePersister.java:151)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.updateValues(EagerLoadingOfBizCustomFieldPersister.java:61)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:108)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:49)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:101)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:43)
at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:143)
at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:728)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:681)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667)
at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217)
at com.atlassian.jira.issue.IssueManager$updateIssue$49.call(Unknown Source)
at Script396.run(Script396.groovy:21)
Caused by: java.lang.NullPointerException: null value in entry: issue=null
at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:32)
at com.google.common.collect.SingletonImmutableBiMap.<init>(SingletonImmutableBiMap.java:42)
at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:72)
at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:124)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.lambda$getValuesForIssueId$0(EagerLoadingOfBizCustomFieldPersister.java:104)
at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4876)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3528)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2277)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2044)
... 20 more

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.7.0
TAGS
Community showcase
Published in Jira Service Management

ThinkTilt is joining the Atlassian Family!

This morning, Atlassian announced the acquisition of ThinkTilt , the maker of ProForma, a no-code/low code form builder with 700+ customers worldwide. ThinkTilt helps IT empower any team in their or...

467 views 20 24
Read article

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