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 issue reporter with ScriptRunner

Hi Community,

I am completely new regarding to ScriptRunner topics and need some good start. In the end I want to perform a simple postfunction as soon as a issue was created. I have an customer field "On behalf of" there customers could create a issue for their colleagues.

My intention is, as soon as this field "On behalf of" != null the system field creator/reporter should be replaced. "On behalf of" is a single-user-picker field as well. A business case could be that a colleague has currently no time to create an issue by themself and another colleagues jumps in without being notified the whole time.

If you have an idea by any chance I would appreciate it.



2 answers

1 accepted

2 votes
Answer accepted


As @Danyal Iqbal says scriptrunner documentation is good place to start.

Second one is this community, there are tons of quiestions and answers with code, just google it :)

And for your example you can use this code in posfunction

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("")

def onbehalfCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("On behalf of")
def onbehalfValue = issue.getCustomFieldValue(onbehalfCustomField)
if (onbehalfValue){

And do not forget to place this postfunction right befoge "Update change history for an issue and store the issue in the database."

Hi Mark,

Just quickly two different questions.


I receive an error [Static type checking] - cannot find matching method. I also checked the API which is actually fine with this function. You mentioned

And do not forget to place this postfunction right befoge "Update change history for an issue and store the issue in the database."

Means I cant do this post-function right after "create", before a customized status steps in? Because I actually need this before any ticket reaches the first status. I am asking because the "Update change history for an issue and store the issue in the databse" action is not mentioned during the first post-function after "create".



Hi Kristian,

This is static type checking error, you can ignore that. This is happens because method getCustomFieldValue defined return object value (actually it can returns Options object Application User object, String object), so compiler doesnt know which one returns and set this error, but we know that from User picker field it will return Application User.

Yes, you can place this after create (main requiriment is that issue object must be created), but if something esle will change reporter after, it will not work.

Hi Mark,

Thanks for your help and time.

The script runs now for each new created issue but unfortunately the reporter doesn´t change. Maybe I did something wrong from the field perspective, anyway thanks.



It seems you have some logic between creates issue and update change history.

Could you provide more information about it?

Hi Mark,

Thanks for your help.

Actually there is no other logic behind. Later during different transitions yes, but non of them affects the reporter. Just email notifications.

As you can see below the script itself executes after each issue. I also switched the position of the script right after "Creates the issue originally". The other steps are default steps during the service desk creation.

Transition Create issue.JPG

I only changed line 4, because the script should affect each issue and not just one specific. I will do some other tests and will inform you about my outcome.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue

def onBehalfOfCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ASD: On behalf of")
def onBehalfOfValue = issue.getCustomFieldValue(onBehalfOfCustomField)

if (onBehalfOfValue){
}"Issue reporter: " + issue.reporter)



Hi Mark,

A quick update.

I adapt some changes which I found in the API. I am able to set the reporter and assignee static as a test but as soon as I put a reference to my customfield the logs says "null" and the ticket assignee changing to "Unassigned" and the reporter to "Anonymous".  We also forgot to store the issue after this changes.

Obvously the reference to the value of the customfield seems wrong. I will keep searching how to set a user picker field proberly.

Below the static code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("HOSD-276")

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ASD: On behalf of")
def newReporter = customField.getValueFromIssue(issue)

if (customField){
    //Reference currently not working
} else {
    //Static works fine
}"Issue reporter: " + issue.reporter)"Issue assignee: " + issue.assignee)



Danyal Iqbal Community Leader Jul 04, 2018
def newReporter = customField.getValueFromIssue(issue)


def onbehalfValue = issue.getCustomFieldValue(customField)


Write a proper postfunction if you want to implement it for every issue on creation or take the easier route below:

Fire a custom event on creation e.g issue_created_set_reporter and . Catch the event in the listener and use event.getissue to  get every issue on creation instead of getting the issue by key.

Hi, Kristian

Regarding your first of two last posts

As i can see on screenshot, postfunction placed before issue creates and obviously that will not work, cause you tryin to set reporter to issue that doesnt exist. Place your postfunction after "Creates the issue originally"

MutableIssue issue = issue

 you can remove this line, postfunction scope itself already contains issue variable.

after this changes your postfunction will be work on all issues.


Regarding second

@Danyal Iqbal already answer you :)

And do not use

it is deprecated and may cause some unexpected bugs

see ref


import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor;

ComponentAccessor.getIssueManager().updateIssue(issue.getReporter(), issue, EventDispatchOption.ISSUE_UPDATED, false)

But in postfunction, if you place postfunction before "Update change history" and Re-index, you dont need to store changes in code.

Hi Mark,

Thanks for the hints. I adjust my script.

I realized as soon as I leave my custom field empty and the if condition should be ignored, I receive "Anonymous" as a reporter. I have two explanations for that:

  1. The custom field throws a value even than not touched
  2. I need to add a else condition with the currently logged user as reporter



0 votes
Danyal Iqbal Community Leader Jul 02, 2018

a good place to start would be the script runner documentation

and the 101 code example below:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()




Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

989 views 7 16
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