Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script runner Listeners is not working

Rajat Krishnan July 28, 2025

Hello Community,

I am trying to automate one of the feature in my jira 8 datacenter environment

Objective:

Inherit parent task text(under description field) of its corresponding sub-task description along with some hard coded text

Listeners:

  • Events: Issue Created
  • Server Side Code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.event.type.EventDispatchOption

def issue = event.issue
if (!issue.issueType?.subTask) {
    return
}

def parentIssue = issue.parentObject
if (!parentIssue) {
    return
}

def parentDesc = parentIssue.description ?: "<No description available>"
def finalDescription = """\
1.Sub Task description:

2.Acceptance criteria:

3.Storage location:

4.Description of mother task:

${parentDesc}
"""

// Run asynchronously so Jira finishes its own processing
Thread.start {
    sleep(4000) // wait 4 seconds for Jira's copy process

    def issueService = ComponentAccessor.getIssueService()
    def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    def issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.setSkipScreenCheck(true)
    issueInputParameters.setDescription(finalDescription)

    def validationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters)
    if (validationResult.isValid()) {
        issueService.update(currentUser, validationResult, EventDispatchOption.ISSUE_UPDATED, false)
    } else {
        log.warn("Description update failed: ${validationResult.errorCollection}")
    }
}
Excepted Output:
While creation of sub-task, description field of sub-task shall contain 
  • Hard coded text i.e.
    • 1.Sub Task description:

      2.Acceptance criteria:

      3.Storage location:

      4.Description of mother task:
  • Inherited text from Parent task i.e.
    • ${parentDesc}
Actual Output:

While creation of sub-task, description field is filled with parent description and not the hard coded text

Can someone please let me know what is going wrong?

Thank you

1 answer

1 vote
Valerie Knapp
Community Champion
July 28, 2025

Hi @Rajat Krishnan , thanks for your post.

First of all, I always recommend to people to have a look at the sample scripts that are provided for this kind of thing, like this one for example, https://www.scriptrunnerhq.com/help/example-scripts/copy-linked-issue-value-onPrem , to not have to start from scratch.

Then, if you have used a sample script to start from and are still having trouble, I would open a ticket to Adaptavist, because this is a paid app and they provide support for this kind of thing - https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=datacenter&tab=support 

Have you already tried this?

I hope this helps you.

Best wishes

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events